# Trying to run an external exe file in ruby

**URL:** <https://www.ruby-forum.com/t/trying-to-run-an-external-exe-file-in-ruby/151230>\
**Category:** Ruby\
**Created:** [October 18, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/trying-to-run-an-external-exe-file-in-ruby/151230 "2008-10-18T17:06:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mooneater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mooneater](https://www.ruby-forum.com/u/mooneater)\
**Post date:** [October 18, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/trying-to-run-an-external-exe-file-in-ruby/151230/1 "2008-10-18T17:06:40Z")

</div>

Hi chaps,

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

currently I have this:

`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")
`

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?

---

<div class="post-metadata">

**Author:** ![mooneater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mooneater](https://www.ruby-forum.com/u/mooneater)\
**Post date:** [October 18, 2008, 9:01pm UTC](https://www.ruby-forum.com/t/trying-to-run-an-external-exe-file-in-ruby/151230/2 "2008-10-18T21:01:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mooneater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mooneater](https://www.ruby-forum.com/u/mooneater)\
**Post date:** [October 19, 2008, 3:24am UTC](https://www.ruby-forum.com/t/trying-to-run-an-external-exe-file-in-ruby/151230/3 "2008-10-19T03:24:24Z")

</div>

William J. 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…
