process.start() isnt working

ive got a program set up so that when i run it, it will run a batch script...

whenever i run the program, it seems as though the script runs fine, but anything that i put into the script doesnt get executed... ive tried having it run an exe, when i ran it through windows, it worked, but didnt through the program, so i tried just putting in "PAUSE" which should display "press any key to continue" i double click on it and it runs flawlessly, i try to run it through the program, and it doesnt work at all

i've included the ref. to system.diagnostics and the exact code which doesnt run is "Process.Start(@"E:\DBB\dbb.bat");"

anyone have any idea whats going on?

this is compiled under VS.net 2003 on a windows xp pro system
[767 byte] By [KB1IBH] at [2007-11-20 11:07:25]
# 1 Re: process.start() isnt working
Will this code start an exe (i.e. @"C:\WINDOWS\system32\Notepad.exe")?

If so, you'll need to start 'CMD' and pass in the bat file as a parameter.

Here's a method to launch a process w/cmd params and wait for it to end

/// <summary>
/// Executes a process and waits for it to end.
/// </summary>
/// <param name="cmd">Full Path of process to execute.</param>
/// <param name="cmdParams">Command Line params of process</param>
/// <param name="timeout">Time to wait for process to end</param>
/// <returns>Process exit code</returns>
private int ExecuteProcess( string cmd, string cmdParams, int timeout )
{
using( Process process = Process.Start( new ProcessStartInfo( cmd, cmdParams ) ) )
{
process.StartInfo.UseShellExecute = false;

process.Start( );

process.WaitForExit( timeout );

return process.ExitCode;
}
}

You would call it as follows

ExecuteProcess( "CMD", @"E:\DBB\dbb.bat" );
Arjay at 2007-11-9 11:36:15 >
# 2 Re: process.start() isnt working
try

Process.Start(@"E:\DBB\dbb.bat", "explorer.exe");

Put [STAThread] before your main method for optimal performance :P

[STAThread]
static void Main()
{
// stuff
]
dahwan at 2007-11-9 11:37:16 >
# 3 Re: process.start() isnt working
[STAThread] has absolutely nothing to do with 'performance'.

'The STAThreadAttribute marks a thread to use the Single-Threaded COM
Apartment if COM is needed'
If anything, you'd choose MTA thread for better performance, but that has other consequences.
Mutant_Fruit at 2007-11-9 11:38:26 >
# 4 Re: process.start() isnt working
Yeah, what i mean is that when i used

Process.Start(@"C://", "explorer.exe");

It took the program about a minute to open the folder. But when i put [STAThread] in front of Main(), it popped up instantly. So in nub terms; it got better performance.
dahwan at 2007-11-9 11:39:21 >
# 5 Re: process.start() isnt working
But STAThread only affects COM interop it has zero performance impact on the Process.Start method.

The only caveat about setting STAThread is this:

A note about apartment states in managed threads is necessary here. When UseShellExecute is true on the process component's StartInfo property, make sure you have set a threading model on your application by setting the attribute [STAThread] on the main() method. Otherwise, a managed thread can be in an unknown state or put in the MTA state, the latter of which conflicts with UseShellExecute being true. Some methods require that the apartment state not be unknown. If the state is not explicitly set, when the application encounters such a method, it defaults to MTA, and once set, the apartment state cannot be changed. However, MTA causes an exception to be thrown when the operating system shell is managing the thread.

That doesn't affect performance though.
Mutant_Fruit at 2007-11-9 11:40:20 >