我最近试图执行以下代码:
string strCmdText;
strCmdText = "netstat -np TCP | find " + quote + number + quote + "";
System.Diagnostics.Process.Start("netstat.exe", strCmdText);
Logs.Write("LISTEN_TO(" + Registry_val1.Text + ")", strCmdText);
现在,基本上需要找到所有TCP端口中包含“80”的端口,并在我的自定义日志系统中显示它们,该系统将在我的文件夹中制作一个名为“LISTEN_TO(80)-{date_time} .txt”的日志册。
在这个.txt文件中,它应该包含所发出命令的文本,然而我得到的只是时间。
我已经调试了上述命令,不幸的是,我只知道CMDtext被正确设置,并且我的日志记录系统工作正常,让我别无选择,只能认为NETSTAT可能在查询启动后立即关闭了吗?
希望我提供了足够的信息,因为这是我的第一篇帖子。
问候,
Co
由于描述模糊,这里是另一种尝试做相同代码的方法,但仍然只能得到时间。
const string quote = "\"";
Process p = new Process();
p.StartInfo.FileName = "cmd";
p.StartInfo.Arguments = "netstat -np TCP | find " + quote + number + quote + "";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
String output = p.StandardOutput.ReadToEnd();
Logs.Write("LISTEN_TO(" + Registry_val1.Text + ")", output);
基本上,你可以将其视为:textbox1.text = output; 但现在输出被放入了日志文件中。