从文件重定向进程输入时出错
我在尝试从文件重定向进程输入时收到输出错误 - 读取文件内容并将其写入进程输入。 错误:<代码><输出文件>;文件的卷已从外部更改,因此打开的文件不再有效。
代码:
*foreach 循环之前:
prc = new Process();
prc.StartInfo.FileName = prcs;
prc.StartInfo.UseShellExecute = false;
*foreachloop 内部:
prc = new Process();
prc.StartInfo.FileName = prcs;
prc.StartInfo.UseShellExecute = false;
if (prcs == asProcesses[0])//first process - only redirect output
{
prc.StartInfo.RedirectStandardInput = true;
prc.StartInfo.RedirectStandardOutput = true;
prc.Start();
sw = prc.StandardInput;
StreamReader sr1 = new StreamReader(sInRedirect);
while ((outputLine = sr1.ReadLine()) != null)
{
sw.Write(outputLine);
sw.WriteLine();
}
sr = prc.StandardOutput;
}
* 我在编写命令时收到消息:“text1.txt < ;排序”
- 另一件事,如果我在另一台计算机上运行该程序,我会收到消息: “管道正在关闭” 感谢您的帮助!
I'm receiving an output error while trying to redirect a process input from a file - reading the file content and writing it to the process input.
the error: <output file> The volume for a file has been externally altered so that the opened file is no longer valid.
the code:
*before foreach loop:
prc = new Process();
prc.StartInfo.FileName = prcs;
prc.StartInfo.UseShellExecute = false;
*inside foreachloop:
prc = new Process();
prc.StartInfo.FileName = prcs;
prc.StartInfo.UseShellExecute = false;
if (prcs == asProcesses[0])//first process - only redirect output
{
prc.StartInfo.RedirectStandardInput = true;
prc.StartInfo.RedirectStandardOutput = true;
prc.Start();
sw = prc.StandardInput;
StreamReader sr1 = new StreamReader(sInRedirect);
while ((outputLine = sr1.ReadLine()) != null)
{
sw.Write(outputLine);
sw.WriteLine();
}
sr = prc.StandardOutput;
}
* i get the message while writing the command: "text1.txt < sort"
- another thing, if i run the program in another computer i get the message:
" the pipe is being closed"
thank you for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
输出目录的权限设置似乎阻止了 Visual Studio 编译。
从项目文件夹和所有子目录中删除所有只读标志,清除输出文件夹,并在必要时取得文件夹的所有权或授予自己完全权限。
来源: msdn - Visual Studio 2010 无法构建或调试报告错误“无法写入输出文件”。
It seems that the permission on your output directory are set in a way that prevents Visual Studio from compiling.
Remove any read-only flags from the project's folder and all subdirectories, clear the output folder and, if necessary, take ownership of the folders or give yourself full permissions.
Source: msdn - Visual Studio 2010 fails to build or debug reports error 'Failed to write to output file'.