0

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?

Sully
  • 14,672
  • 5
  • 54
  • 79
  • 1
    Calling batch files running under Wine on an Ubuntu server does not sound like a good idea. Maybe you should rewrite those batch files into shell or Ruby scripts? – Blender Apr 03 '13 at 03:29
  • I'm stuck with the Ubuntu server due to cost differences. I considered rewriting the batch files, but there are a significant amount of them and would require a non-trivial amount of work. So if there was a way to call them through Wine on Ubuntu (even if it may not be the best design), that could serve as a quick fix for now. Then I could go back and transition them over time – user2238231 Apr 03 '13 at 03:43
  • I would convert the bat files to sh syntax – Sully Apr 03 '13 at 04:15
  • You're gonna have a bad time... I wouldn't say its impossible but like Blender said, I would definitely recommend rewriting them. – Snarf Apr 03 '13 at 04:16

1 Answers1

0

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.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • Thanks, this worked with a slight modification: `system 'wine', 'cmd.exe', '/C', @batch_file, self.infile, self.outfile, self.param1, self.param2` The batch file actually had to be stored in a variable or it would come back with a "syntax error, unexpected tlVAR, expecting kEND" – user2238231 Apr 03 '13 at 15:56