|
-
June 8th, 2005, 06:23 AM
#1
Running DOS inside C#
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??
-
June 8th, 2005, 06:59 AM
#2
Re: Running DOS inside C#
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
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
Code:
p.StandardInput.WriteLine(@"chdir \MyPerlDirectory");
And then run the above command...
HTH
-
June 8th, 2005, 08:02 AM
#3
Re: Running DOS inside C#
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|