Click to See Complete Forum and Search --> : Running DOS inside C#


yiannakop
June 8th, 2005, 06:23 AM
Hi. I need to run an exe using DOS inside my C# programm. I have found some things about running DOS command prompt, but they are about running internal DOS commands like dir,etc. I want to run an exe the syntax of which is iehv /stext c:\\urls.txt and another exe which uses perl and the syntax is perl extract.pl test.htm > test.out. I tried the follwoing code:
ProcessStartInfo startinfo;
Process p = null;



startinfo = new ProcessStartInfo("cmd.exe");


startinfo.RedirectStandardInput=true;
//startinfo.RedirectStandardOutput = true;

// don't exec with shellexecute api
startinfo.UseShellExecute = false;

// redirect stdout to this program
//startinfo.RedirectStandardOutput = true;

// don't open a cmd prompt window
//startinfo.CreateNoWindow = true;

// start cmd prompt, execute command
p = Process.Start(startinfo);

p.StandardInput.WriteLine(@"perl extract.pl test.htm > test.out");
p.StandardInput.WriteLine(@"exit");
//string output = p.StandardOutput.ReadToEnd();
//password.Text=output;

If I use an internal command like dir the command does execute. If I use the commands I need though, I get no output.
Can anyone help??

Shuja Ali
June 8th, 2005, 06:59 AM
It is not that you can just execute Internal Commands, you can execute any EXE/COM file present on your system, provided the path of that file is set-up in Environment Variable (Path)..

For your code

p.StandardInput.WriteLine(@"perl extract.pl test.htm > test.out");

Setup up the Path of perl file and then try!
Or
Just change the directory to the location where your files exist and then run your Perl compiler/command...
Something like this

p.StandardInput.WriteLine(@"chdir \MyPerlDirectory");

And then run the above command...

HTH

rockytriton
June 8th, 2005, 08:02 AM
Also, just FYI, cmd.exe isn't DOS, it's the windows console. DOS doesn't exist in NT/2k/XP anymore. command.com was the DOS command prompt in older versions of windows.