Perl.exe could not be called ProcessStartInfo

I am trying to get the following code to work, so I can call the perl script from my C #. I am developing using Visual Stdio 2008 in xp service pack3.

myProcess = new Process(); ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("perl.exe"); myProcessStartInfo.Arguments = @"C:\Documents and Settings\test_perl.pl"; myProcessStartInfo.UseShellExecute = false; myProcessStartInfo.RedirectStandardOutput = true; myProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden; myProcessStartInfo.CreateNoWindow = true; myProcess.StartInfo = myProcessStartInfo; myProcess.Start(); string output = myProcess.StandardOutput.ReadToEnd(); MessageBox.Show(output); myProcess.WaitForExit(); 

I check if test_perl.pl exists, and if I change the perl.exe file to notepad.exe, it works on this code. But if I use perl.exe, the message field is empty.

I can’t understand why this is wrong. Please help me if you know why.

thanks

+4
source share
2 answers

Can perl.exe handle unquoted paths containing spaces on the command line? Try to specify the path:

 myProcessStartInfo.Arguments = @"""C:\Documents and Settings\test_perl.pl"""; 

Since the command line arguments are separated by spaces, unless the file path is specified, the application (perl.exe, in this case) will see three arguments:

  • C: \ Documents
  • and
  • Settings \ test_perl.pl

Perl will most likely try to open the file "C: \ Documents". Of course, this does not exist. The solution is to specify file paths that contain spaces (or all file paths to be sequential).

You note that notepad.exe handles unquoted file paths very well. This is probably just a notepad smarter than the average bear and merging its arguments for you.

And make sure the file exists on this path, of course. This is actually a little unusual way; usually you will see user files in the form C: \ Documents and Settings \ myusername \ Documents \ file.ext or such.

+6
source

Is perl in your %PATH% ? Open a command prompt and type " perl -v "

0
source

All Articles