我试图得到以下代码的工作所以我可以叫一个perl从我的脚本 c#程序。我是发展中使用的视觉stdio2008年xp服务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();

我验证test_perl.pl 存在,如果我改变的perl.exe 要notepad.exe,此上述代码的工作。但是,如果我使用perl.exe,消息盒子是空的。

找不出为什么这个是错误的。请帮助我,如果你知道为什么。

感谢

有帮助吗?

解决方案

可以perl.exe 处理不带引号的路径包含空间的命令行?试着引用的路径:

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

由于命令行参数分隔的空间,除非文件路径是引用的应用程序(perl.exe在这种情况下)会见三个参数:

  1. C:\Documents
  2. Settings est_perl.pl

Perl可能会试图打开的文件"C:\Documents".这并不存在的,当然。该方案是报价文件路径包含空间(或所有文件路径,是相一致)。

你说过notepad.exe 处理没有引用的文件路径的罚款。有可能的,这只是记事本被聪明平均承担和合并其论点。

和验证文件存在这条道路,当然。这实际上是一个略有不同寻常的路径;通常,你会看到用户的文件中喜欢的东西 C:\Documents 并且设置\名为myusername\文件\文件。ext, 或者这样的。

其他提示

时的perl在%PATH%?打开命令提示和在“perl -v”键入

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top