|
-
Oct 17th, 2003, 11:30 AM
#1
Thread Starter
New Member
cmd.exe and sendwait not working
I am trying to write an application that starts the command prompt then executes a few strings using SendKeys.SendWait and then when that is done I want to run a different executable that uses files created from the command prompt execution session.
My problem is that the sendwait command doesn't seem to wait for the command prompt to finish before going on to the next command. Does anyone know why or a way around this?
Thanks!
-
Oct 17th, 2003, 01:48 PM
#2
use the System.Diagnostic.Process class, and redirect the standard input and output. Here's a little snippet from something I did (C#):
Code:
namespace PluginDev
{
public class Zork : IPlugin_v1
{
// ...
private ZorkSettings Settings;
private Process ZorkProc;
// ...
public bool Initialize(IHost host)
{
// ...
ZorkProc = new Process();
ProcessStartInfo ps = new ProcessStartInfo(Settings.ZorkDirectory + "zork1.bat");
ps.RedirectStandardOutput = true;
ps.RedirectStandardInput = true;
ps.UseShellExecute = false;
ps.WorkingDirectory = Settings.ZorkDirectory;
ZorkProc.StartInfo = ps;
return (ZorkProc.Start());
}
Then you can use the streams to write to / read from the console:
Code:
ZorkProc.StandardInput.WriteLine("my text");
string s = ZorkProc.StandardOutput.ReadLine();
If you're dealing with the command prompt, you need to start cmd.exe (nt/xp/2k) or command.com (9x) instead of zork1.bat like I did 
Hope that helped!
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Oct 17th, 2003, 05:28 PM
#3
Thread Starter
New Member
Thanks for your reply.
That does allow me to write information to the command prompt, but it doesn't wait for the command prompt to finish processing my data.
For instance, I run make_dat.exe < run.imp in the command prompt.
make_dat.exe takes a few minutes to process and create the files. I then want to kill the command prompt. I then want to start the process tecplot.exe to input the files created by make_dat.exe.
The problem is, I have no way to pause the program while make_dat.exe is running in the command prompt. I thought SendWait would do this, but it doesn't seem to work in this instance.. Tecplot automatically starts up and the files it needs have not yet been created.
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
|