如何使用asp.net C#重定向的命令提示符输出到文件? [英] How to redirect command prompt output to a file using asp.net C#?

查看:116
本文介绍了如何使用asp.net C#重定向的命令提示符输出到文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图重定向的命令提示符输出使用Asp.Net C#的文件。

I have tried to redirect the command prompt output to a file using Asp.Net C#.

System.Diagnostics.Process si = new System.Diagnostics.Process();
si.StartInfo.WorkingDirectory = "c:\\";
si.StartInfo.UseShellExecute = false;
si.StartInfo.FileName = "cmd.exe";
si.StartInfo.Arguments = @"/c dir" +">" + @"Myval.txt";
si.StartInfo.CreateNoWindow = true;
si.StartInfo.RedirectStandardInput = true;
si.StartInfo.RedirectStandardOutput = true;
si.StartInfo.RedirectStandardError = true;
si.Start();
string output = si.StandardOutput.ReadToEnd();
Response.Write(output);
si.Close();

是越来越成功创建的文件,但它没有内容present。
即使变量输出返回任何内容。
帮我解决这个问题。

The file is getting created successfully but no content present in it. Even the variable Output returns nothing. Help me to resolve this issue.

推荐答案

修正后编辑:

我刚刚测试了我的机器和code完美的作品。我不读,仔细测试自己道歉。创建Myval.txt和DIR输出写入到它。

I just tested on my machine and the code works perfectly. I apologize for not reading and testing carefully myself. Myval.txt is created and the DIR output is written into it.

输出变量,因为你是通过重新路由DIR命令到txt文件的任何输出,所以这是由设计是空的。

The output variable is empty because you are rerouting any output by the DIR command into the txt file, so that's by design.

请查看是否有对txt文件$ P $被覆盖pventing任何锁。而且重要的是,我只能猜测,有一个安全问题$ P $运行pventing DIR命令。

Please see if there are any locks on the txt file preventing it from being overwritten. Further than that, I can only guess that there is a security issue preventing the DIR command from running.

这篇关于如何使用asp.net C#重定向的命令提示符输出到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆