Question

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.

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

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

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:

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'

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

Was it helpful?

Solution

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

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top