【发布时间】:2013-11-24 23:52:57
【问题描述】:
我有一个需要调用 perl 脚本的 c# 服务。现在我的桌面上有 perl 脚本,只引用桌面的完整路径。是否可以将 perl 脚本添加到 c# 项目并将其构建到与构建后生成的 .exe 相同的目录?这样就可以从当前路径引用该文件。代码如下。 perl 脚本还使用了我不希望在脚本中使用的敏感信息,最好的方法是通过 c# 将敏感信息作为参数传递吗?
谢谢,
ProcessStartInfo perlStartInfo = new ProcessStartInfo(@"C:\strawberry\perl\bin\perl.exe"); perlStartInfo.RedirectStandardInput = true; perlStartInfo.UseShellExecute = false; perlStartInfo.CreateNoWindow = true; 进程 perl = new Process(); perl.StartInfo = perlStartInfo; perl.Start();
byte[] byteArray = Encoding.ASCII.GetBytes(Properties.Resources.TransferChange);
using (MemoryStream stream = new MemoryStream(byteArray))
{
stream.CopyTo(perl.StandardInput.BaseStream);
// this will cause perl to execute the script
perl.StandardInput.Close();
}
perl.Start();
perl.WaitForExit();
string output = perl.StandardOutput.ReadToEnd();
我添加了 perl.Start();到代码。我一直到 perl.WaitForExit();但它只是挂在那里。有什么想法吗?
【问题讨论】:
-
将其添加到项目并设置为在构建期间复制...这是您需要的吗?