Command Prompt use within C# class file
I am making a console application whose sole user interaction is form based. Lets say there is a button on my main form which, when clicked, must run another program via command prompt. I've been trying to find a way to do the following steps in a hardcoded manor:
1) open a command prompt
2) change the directory to the folder path the other program lies in
3) run said program
All of these would preferably be done without the command prompt being visible to the user. So far I've achieved step 1, which seemed the easy part. I can't however figure out how to input commands to the prompt, which is what is needed to do the next two steps.
I've been opening command prompt by writing
ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe");
and then
Process.Start(startInfo);
after I changed aspects like startInfo.CreateNoWindow
I'd very much appreciate some direction here. Also, please let me know if you'd like additional information.
Not a C# expert yet, but...
cStudy,
Rather than:
Quote:
Originally Posted by
theoobe
Try this...
Code:
String path = "c:\\whatever the folder path"; // set the path folder containing perl.exe and the .pl files
Process.Start(path + "\\perl.exe", path + "\\processName.pl");
May I suggest:
Code:
String path = "c:\\path to perl files"; // set the path folder containing the .pl files
// ...
sw.WriteLine( "cd" + path );
sw.WriteLine( "perl process.pl" );
// ...
You also used a ProcessStartInfo object, which looks nifty by the way, what did you give it as a path (to search for executables I mean)? Does the path to the perl executable also need to be given during the second WriteLine?
Best Regards,
New Ink -- Henry