[CF 2.0] Process.Start questions

S

Steve B.

Hi,

I use ProcessStartInfo and Process.Start to run a command line application.
I have two questions :

1. Is there a size limit to the command line arguments ?

2. How can I easily get results from the command line application ?

Thanks,
Steve
 
C

chris-s

Is the 'command line application' one that you have written yourself?
If so, can you store the result into the registry or a file or maybe
create/delete a file with a specified name to indicate the result being
returned?

Back in the days of DOS, you use to be able to exit an application with
a 'result code' and then pick this up, not sure whether the same is
available now tho.

Chris
 
S

Steve B.

The app I'm launching is an app written in C# too...
I've not found how to fix the exit code of the process in C#.

Writing a file is a possible way, but I don't found this solution pretty...

Thanks,
Steve
 
H

Hank

See if this doesn't work: (this code is using CF 2.0, if you can't use that,
use OpenNETCF's API -- same syntax)

System.Diagnostics.ProcessStartInfo psi = new
System.Diagnostics.ProcessStartInfo(myExe, args);

psi.UseShellExecute = false;

System.Diagnostics.Process process = null;

process = System.Diagnostics.Process.Start(psi);

// Wait until process exits. Timeout should be enough to have it make

// sense to kill process if it expires.

bool exited = process.WaitForExit(timeout);


if (exited)

int exitCode = process.ExitCode;
 
S

Steve B.

The call of the second app is not a problem... the process class has a
ExitCode property.

What I don't know how to do is to SET the exit code of the called
application.

Steve
 
G

Guest

I've never needed it, but what I'd try is P/Invoking ExitThread in the
called process (which takes the exit code as a parameter) and see if that's
what the Process class uses internally (can't think of what else it might
be).

-Chris
 
S

Steve B.

According the PPC 2003 SDK, I added this line to my program :

[System.Runtime.InteropServices.DllImport("coredll.dll")]

private static extern void ExitProcess(uint uExitCode);



However, when the code call this method, I've an exception telling me the
entry point is not found in the coredll.dll :

System.MissingMethodException was unhandled
Message="Point d'entrée 'ExitProcess' introuvable dans la DLL PInvoke
'coredll.dll'."
StackTrace:
à MyApp.Program.Main()

Is the P/Invoke corretly declared ?



Thanks,

Steve
 
S

Sergey Bogdanov

There is no ExitProcess function. It's just a macros:

#define ExitProcess(code) TerminateProcess (GetCurrentProcess (), (code))



--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

According the PPC 2003 SDK, I added this line to my program :

[System.Runtime.InteropServices.DllImport("coredll.dll")]

private static extern void ExitProcess(uint uExitCode);



However, when the code call this method, I've an exception telling me the
entry point is not found in the coredll.dll :

System.MissingMethodException was unhandled
Message="Point d'entrée 'ExitProcess' introuvable dans la DLL PInvoke
'coredll.dll'."
StackTrace:
à MyApp.Program.Main()

Is the P/Invoke corretly declared ?



Thanks,

Steve




I've never needed it, but what I'd try is P/Invoking ExitThread in the
called process (which takes the exit code as a parameter) and see if
that's what the Process class uses internally (can't think of what else it
might be).

-Chris
 

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