[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
executed.

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
mono/mono/metadata/process.c

The most important is this:

#ifdef PLATFORM_WIN32
  spath = g_getenv ("COMSPEC");
  shell_args = "/c %s";
#else
  spath = g_getenv ("SHELL");
  shell_args = "-c %s";
#endif

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.

Kornél



More information about the Mono-list mailing list