1

Let's say i have button on my form (i use c#)

private void yesButton_Click(object sender, EventArgs e)
{
}

how and what i need to write, so that i can call my ruby cmd file?

for example in cmd i write:

cd c:\ruby\ 
ruby 1.rb 
(here i need to pass some var's) 
root 
123

how can i call this in my c# .net app? also i need to see cmd output on some form component (which is best) ?

also i need to call this in "multi-task", so call this cmd let's say 10 time in ~ on time...

Valdis Azamaris
  • 1,433
  • 5
  • 22
  • 47

1 Answers1

1

Alright, so you're question is still real vague, but you can do it like this:

var pathToRbFile = @"C:\Ruby193\script\123.rb";
var arguments = string.Empty; // I don't know what the arguments would be

var info = new ProcessStartInfo(pathToRbFile, arguments);
Process.Start(info);
Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
  • wouldn't the .rb file be the argument and the first parameter the path to the ruby executable in this case? otherwise this should work. – krizz Nov 20 '13 at 14:28
  • @krizz, the `.rb` file should already be executable by the shell in general. `Process.Start` leverage the normal shell execution. – Mike Perrenoud Nov 20 '13 at 14:29
  • @ValdisAzamaris, I don't know all of that information because I don't know anything about ruby. But as I stated in my answer, the first parameter is the fully qualified path to the `.rb` file and then the second parameter is a `string` of arguments. What that path is, and what those arguments are, that's something you'll have to work out. – Mike Perrenoud Nov 20 '13 at 14:52
  • forget about ruby, just imagine that i have rb file in "C:\\Ruby193\\scripts" and there i must execute command ruby 123.rb, how to write code than? also give full code, with creating class instance etc – Valdis Azamaris Nov 20 '13 at 14:55
  • @ValdisAzamaris, I've updated my question, but that is all the code. That's all there is to it. – Mike Perrenoud Nov 20 '13 at 15:02
  • wait, first i must CD to folder, and then run second command: "ruby 123.rb", how to do then? i must create one more var info = new ProcessStartInfo(pathToRbFile, arguments); ? – Valdis Azamaris Nov 20 '13 at 15:06
  • @ValdisAzamaris, the code I have will run the ruby file. You're not on the command-line where you need to execute each of those commands. The operating system is going to run the file specified in the path using the shell. – Mike Perrenoud Nov 20 '13 at 15:07
  • main problem is that ruby file will not run so, it's must be run only from cmd, with command: ruby 123.rb - so get's on, if i write as you, it will be opened with text editor ^) so all operation's must be in cmd – Valdis Azamaris Nov 20 '13 at 15:08
  • @ValdisAzamaris, that's just because you haven't associated the file extension with the `ruby` executable. Have a look at the answer in this question: http://stackoverflow.com/questions/1422380/how-to-i-launch-a-ruby-script-from-the-command-line-by-just-its-name – Mike Perrenoud Nov 20 '13 at 15:10
  • ok, i will accept, also maybe you know how to append this output to form ? – Valdis Azamaris Nov 20 '13 at 15:14
  • so i mean this new windows set as tab on form? – Valdis Azamaris Nov 20 '13 at 15:26
  • @ValdisAzamaris, have a look at this answer on how to redirect the output: http://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output – Mike Perrenoud Nov 20 '13 at 15:32
  • i will do this... just 5 min later – Valdis Azamaris Nov 20 '13 at 15:32
  • System.ComponentModel.Win32Exception: this file is not executable Win32. ((( – Valdis Azamaris Nov 20 '13 at 15:38
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/41551/discussion-between-michael-perrenoud-and-valdis-azamaris) – Mike Perrenoud Nov 20 '13 at 15:50