1

I have a method which starts a process. The process is a ruby script which queries an external source and returns something which is printed to a text file 'output.txt' and placed in the directory.

During execution, I run that method which looks like this:

p.StartInfo.FileName = @"blah directory";
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
p.Start();
p.WaitForExit();

Then in my other method I say:

processmethod();
StreamReader sr = new StreamReader ("output.txt");

For some reason the ruby script is not finishing, because it isnt creating the output.txt file. I know it isnt a problem with the ruby script because if I execute it manually it works fine.

I'm guessing its some sort of timing issue. The weird thing is, this was working fine until yesterday with no alterations to that area of the code. I saw somewhere that 'waitforexit' locks the thread too so I'm not sure how this is getting to the streamreader at all without he process actually finishing first.

It also appears that the process simply terminates when the code moves on to the streamreader line, because the window closes and I still dont have an output file

Josh Bibb
  • 477
  • 4
  • 14
  • Do the suggestions here help? http://stackoverflow.com/questions/2285288/calling-a-ruby-script-in-c-sharp – keyboardP Oct 31 '12 at 19:28
  • The Process class doesn't expect parameters as part of the file name. My guess is that you're starting ruby with no script and thus waiting for the interactive shell to terminate. – Brian Rasmussen Oct 31 '12 at 19:47
  • @keyboardP I dont know how the selected answer there even worked because you cant put 'ruby' in the filepath in info... But thank you, although none of those solutions were useful to me – Josh Bibb Oct 31 '12 at 19:51
  • @BrianRasmussen "blah directory" is not what I'm actually passing in there. The filepath to the rb file I'm running is classified so I cant put it on here. But it is something in the format of /rubyfile.rb. Putting the window style to normal, I can confirm that the script IS starting and running correctly up to the point where it prematurely terminates because the c# code wants to move on – Josh Bibb Oct 31 '12 at 19:53
  • @JoshBibb - Try using `p.StartInfo.FileName(@"ruby");` and passing your filename as an argument in `p.StartInfo.Arguments` (then use the rest of the code in the posts). – keyboardP Oct 31 '12 at 19:55
  • @keyboardP you cant set filename(anything) because filename isnt a method, but I knew what you were trying to say. I tried setting the filename to my ruby interpreter and the argument to the script directory and that didnt even open the script. I already have all the code written to deal with the output.txt file and know that it works that way because It worked for a week without issue until the other day. – Josh Bibb Oct 31 '12 at 20:09

0 Answers0