Forum: Ruby Trying to run an external exe file in ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C43defed56b0b2fda1c4aaf8b6a39415?d=identicon&s=25 Thijs Janzen (mooneater)
on 2008-10-18 17:06
Hi chaps,

I'm trying to write a little script that can run several
programs after eacht other.

currently I have this:

[code]require "ftools"
maxAlpha = 1.0 * 1/10
 name3 = "MaxAlpha_"+ maxAlpha.to_s
 target = name3
value = "0\n" + maxAlpha.to_s
File.open('feed.txt', 'w') do |f2|
  f2.puts(value)
$end
system("E:\\Ruby_things\\Mastermind.exe")
[/code]

Now, the Mastermind.exe is supposed to create a config file, based on
the input he reads from "feed.txt". When executed from outside ruby, it
creates a perfect configfile. When, however, Mastermind.exe is called
from within ruby, using the script as above, it all of a sudden is not
able to create output based on "feed.txt". It is able to open it, but
read in values are not stored anymore, and thus not written to the
config file.

Are there any restrictions or such to running C++ based exe files from
within ruby?
2ee1a7960cc761a6e92efb5000c0f2c9?d=identicon&s=25 William James (Guest)
on 2008-10-18 21:01
(Received via mailing list)
Thijs Janzen wrote:

>  target = name3
> called from within ruby, using the script as above, it all of a
> sudden is not able to create output based on "feed.txt". It is able
> to open it, but read in values are not stored anymore, and thus not
> written to the config file.
>
> Are there any restrictions or such to running C++ based exe files from
> within ruby?

Are you sure that Mastermind.exe is looking in the correct
directory?  I believe that the current directory for the exe
will be the directory in which Ruby was invoked.
C43defed56b0b2fda1c4aaf8b6a39415?d=identicon&s=25 Thijs Janzen (mooneater)
on 2008-10-19 03:24
William James wrote:
> Thijs Janzen wrote:
>
>>  target = name3
>> called from within ruby, using the script as above, it all of a
>> sudden is not able to create output based on "feed.txt". It is able
>> to open it, but read in values are not stored anymore, and thus not
>> written to the config file.
>>
>> Are there any restrictions or such to running C++ based exe files from
>> within ruby?
>
> Are you sure that Mastermind.exe is looking in the correct
> directory?  I believe that the current directory for the exe
> will be the directory in which Ruby was invoked.

yes, that is correct.
Actually, the ruby file, and the Mastermind.exe file are in the exact
same directory.

Mastermind.exe does indeed run, it creates the config.ini, BUT the
parameter that is supposed to have 'feeded' to it, by means of reading
out "feed.txt", is NOT passed on to the config.ini...
This topic is locked and can not be replied to.