在Linux中使用Ruby on Rails通过Wine运行Windows批处理文件

时间:2022-12-20 02:17:25

I'm developing a web application using Ruby on Rails and running it on a Linux (ubuntu) server. My backend processing is based on a Windows .bat file that calls a network of other .bat files based on a list of about 5 parameters.

我正在使用Ruby on Rails开发一个Web应用程序并在Linux(ubuntu)服务器上运行它。我的后端处理基于Windows .bat文件,该文件基于大约5个参数的列表调用其他.bat文件的网络。

So basically, I'm trying to call the initial batch file with command line preferences through wine in my Rails application.

所以基本上,我试图通过我的Rails应用程序中的wine调用带有命令行首选项的初始批处理文件。

For example, this is similar to what I use to successfully run the code in the ubuntu terminal:

例如,这与我在ubuntu终端中成功运行代码所使用的类似:

wine cmd.exe /C InitialCallFile.bat Directory/Input.xml Directory/Output.xml param1 param2

I tried to call it with the System and %x commands in Ruby. For example:

我试图用Ruby中的System和%x命令调用它。例如:

System "wine cmd.exe /C InitialCallFile.bat self.infile self.outfile self.param1 self.param2"
system wine cmd.exe InitialCallFile.bat [self.infile, self.outfile, self.param1, self.param2]
%x[wine cmd.exe /C InitialCallFile.bat self.infile self.outfile self.param1 self.param2]

and other similar variations

和其他类似的变化

However, the program doesn't recognize cmd and comes back with the error: undefined local variable or method `cmd'

但是,程序无法识别cmd并返回错误:未定义的局部变量或方法`cmd'

How should I go about correctly calling an application in wine using Ruby on Rails?

我应该如何使用Ruby on Rails正确调用wine中的应用程序?

1 个解决方案

#1


0  

You should be able to use system (note the lower case s), preferably the multi-argument form:

你应该能够使用系统(注意小写s),最好是多参数形式:

system 'wine', 'cmd.exe', '/C', 'InitialCallFile.bat', self.infile, self.outfile, self.param1, self.param2

Note that the constant parts are string literals whereas as the variable parts (such as self.infile) are method calls and so they're not quoted.

请注意,常量部分是字符串文字,而因为变量部分(例如self.infile)是方法调用,因此它们不会被引用。

You could also use string interpolation to build the command but that's a really bad idea and I'm not going to encourage bad habits by showing you how.

你也可以使用字符串插值来构建命令,但这是一个非常糟糕的主意,我不会通过向你展示如何来鼓励坏习惯。

#1


0  

You should be able to use system (note the lower case s), preferably the multi-argument form:

你应该能够使用系统(注意小写s),最好是多参数形式:

system 'wine', 'cmd.exe', '/C', 'InitialCallFile.bat', self.infile, self.outfile, self.param1, self.param2

Note that the constant parts are string literals whereas as the variable parts (such as self.infile) are method calls and so they're not quoted.

请注意,常量部分是字符串文字,而因为变量部分(例如self.infile)是方法调用,因此它们不会被引用。

You could also use string interpolation to build the command but that's a really bad idea and I'm not going to encourage bad habits by showing you how.

你也可以使用字符串插值来构建命令,但这是一个非常糟糕的主意,我不会通过向你展示如何来鼓励坏习惯。