运行 通过 C# 应用程序使用提示的 perl 脚本

Running a perl script that uses a prompt through a C# application

正在尝试从我的 C# 应用程序调用 Perl 脚本。 perl 脚本有一个提示,要求用户在其中输入一些内容。我似乎无法显示它。这是我用来调用它的功能。我有另一个函数,将 System.Enviroment.SetEnvironmtVariable 设置为具有 "C:\Perl\bin\;" 的路径以及其他进程所需的其他路径'

private void getRevisionAndUpdate()
{
    Process myProcess = new Process();
    myProcess.StartInfo.FileName = "cmd.exe";
    myProcess.StartInfo.WorkingDirectory = @"the directory that has the perl script";
    myProcess.StartInfo.Arguments = @"/c SaidPerlScript.pl";
    myProcess.StartInfo.UseShellExecute = false;
    myProcess.Start();
    myProcess.WaitForExit();
}

正如我之前所说,它似乎 运行,但它要么只是在记事本中打开脚本,要么什么都不做。还应注意我已经尝试 运行ning cmd.exe 和 perl.exe。 cmd 似乎在记事本中打开它,而 perl 没有显示它应该显示的提示。

不太清楚你为什么要 运行 cmd.exe,但是如果你通过 perl.exe 运行 它就可以了(我的脚本叫做 a.pl 并打印 hello):

    static void Main(string[] args)
    {
        Process myProcess = new Process();
        myProcess.StartInfo.FileName = "perl.exe";
        myProcess.StartInfo.WorkingDirectory = @".\";
        myProcess.StartInfo.Arguments = @"a.pl";
        myProcess.StartInfo.UseShellExecute = false;
        myProcess.Start();
        myProcess.WaitForExit();
    }

它也能正确读取 STDIN。作为参考,这是 a.pl:

print("Hello\n");
my $a = <STDIN>;
print "You entered " . $a . "\n";