Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing other programs from C#/.NET 1

Status
Not open for further replies.

TwinJon

Programmer
Jul 19, 2003
1
US
Please help me.

I am writing a program in C# using Visual Studio .NET. I want my program to start (launch? spawn?) other existing programs. The other programs are either MS-DOS batch files or normal (non-managed) EXE files.

Can you tell me how to start/spawn (a) another managed (.NET) program and (b) other non-managed EXE or .bat files from a program running inside the .NET framework?

I am running all this under Windows XP.

Thanks,

Jon
 
You can start another program (managed and unmanaged) via the Process.Start() method in the System.Diagnostics namespace. You have to fill out a ProcessStartInfo class, where you specify the path to the executable to run, arguments to be passed on the command-line to the other program, whether to redirect the stdio file handles (StandardInput, StandardOutput, and StandardError), and you can set the working directory for the new process.

Once the new process is started (the call to Start returns another instance of the Process class), you can monitor the other process, getting the memory usage, window title, and importantly, pass input to the other program (if it uses stdin for it's input) via a streamwriter and the StandardInput property.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top