尝试从我的 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();
}
正如我之前所说,它似乎可以运行,但它要么只是在记事本中打开脚本,要么什么都不做。还应该注意我尝试运行 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";
关于c# - 通过 C# 应用程序运行使用提示的 perl 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39603377/