starting a program from C#

D

Dave

I have a filewatcher window service that runs a query. When the query is
done and 2 reports are created, i need to xcom the files to a mainframe. I
am trying to run the process from c# using the following method:
System.Diagnostics.Process.Start(@"D:\xcomnt\xcomtcp.exe -c -f",
@"D:\mainframe.cnf"); It gives me an eror saying that it can't find the
file.
Thanks for the Help

Dave
 
S

Scott M.

System.Diagnostics.Process.Start(file or exe name) is correct. I don't code
in C#, but what is the @ for?
 
M

Michael S

Scott M. said:
System.Diagnostics.Process.Start(file or exe name) is correct. I don't code
in C#, but what is the @ for?

It's a literal string.

@"d:\path\filename.ext" == "d:\\path\\filename.ext"

- Michael S
 
M

Michael S

Dave said:
System.Diagnostics.Process.Start(@"D:\xcomnt\xcomtcp.exe -c -f",
@"D:\mainframe.cnf");

My first guess is that the -c -f arguments should not be part of the
filename.
I usually stay away from the static method Start and use an instance for
clarity.

myProcess = new Process()
myProcess.Filename = @"D:\xcomnt\xcomtcp.exe";
myProcess.Arguments = @" -c -f D:\mainframe.cnf";
myProcess.Start();

Above not tested.

- Michael S
 
P

Pete Davis

You are correct. I ran into this same problem myself. Pass all of your
arguments as the second parameter as follows:
System.Diagnostics.Process.Start(@"D:\xcomnt\xcomtcp.exe", @" -c -f
D:\mainframe.cnf");

Pete
 
A

Alex

First of all .. as Michael S. said , you have to fill the Process.Arguments
property ..

Second thing ..( it's something I've waisted a lot of time to understand and
would like to share this with , so you won't have to waist time)

If you want to wait for that exe to finish running , then right after
calling the
Process.Start method , call Process.WaitForExit.
That way your code will continue only after the exe will exit , otherwise it
just
executes the exe and your program continues it's run ..

Good Luck
 
K

Ken Onweller \(.NET MCSD\)

Another trick you can do if you don't mind using some threading is to keep
track of the start-time of the
process and then check the HasExited property periodically. If the
HaxExited property returns false you
compare the current time against the start time for the process. If too
much time has passed (up to you
to determine this) then you can assume you have a stale job and use the
Kill() method to terminate.
 
D

Dave

Got it to work. Thanks for the help

Dave
Ken Onweller (.NET MCSD) said:
Another trick you can do if you don't mind using some threading is to keep
track of the start-time of the
process and then check the HasExited property periodically. If the
HaxExited property returns false you
compare the current time against the start time for the process. If too
much time has passed (up to you
to determine this) then you can assume you have a stale job and use the
Kill() method to terminate.


otherwise mainframe.
 
G

Guest

Good day!

To wait for that exe to finish running, which of the following is the recommended way?

Case 1
--------
process.WaitForExit();
if(process.HasExited)
{
do next...
}

Case 2
--------
while(!process.HasExited)
{
continue;
}
do next...

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top