[Mono-list] command line apps from ASP.NET

Kornél Pál kornelpal at hotmail.com
Fri Jul 22 11:16:18 EDT 2005

> In the second (the C# source for an asp.net page), I am using
> GACRead.StartInfo.RedirectStandardOutput = true; To use this,
> UseShellExecute must be false, else the error:
> System.InvalidOperationException: UseShellExecute must be false when
> redirecting I/O.

Then you have to specify the shell executable as FileName and the command
line (current FileName + Arguments) as Arguments

>> I think you should put the entire command line to FileName
>> and use UseShellExecute = true (default).
> I get the error:
> System.ComponentModel.Win32Exception: Cannot find the specified file
> If I put the entire command within the FileName (obviously with
> UseShellExecute = false;).

I told you to use UseShellExecute = true, but you used UseShellExecute =
false so it's because of you.:) When UseShellExecute = true shell will be

As you cannot use UseShellExecute = true with RedirectStandardOutput = true
you have to reproduce what the runtime does.

Look at the source code of
ves_icall_System_Diagnostics_Process_Start_internal in

The most important is this:

  spath = g_getenv ("COMSPEC");
  shell_args = "/c %s";
  spath = g_getenv ("SHELL");
  shell_args = "-c %s";

You can get the shell executable from an environment variable and use /c
or -c depending on the platform.

There is nothing in UseShellExecute dependent code that you couldn't
reproduce. And I think you are using Linux only because the command line
itself uses GNU utilities so you don't have to create platform independent
code if you don't need it.


More information about the Mono-list mailing list