在过去的几天里,我一直在学习一些关于ASP的东西。我想把这行PHP代码转换成ASP,但我有点坚持不下去了:
$online = exec('netstat -a -n |find "5816" |find "ESTABLISHED" /c') +1;我尝试创建一个变量来存储数据,但无法弄清楚如何检查端口5816和计算连接数量。感谢您的帮助!
它基本上应该是在cmd中运行的命令,用于检查端口和no。由它建立的连接!
发布于 2016-03-28 13:36:26
执行命令以获取其输出
您可以使用以下代码来执行上述命令:
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = new System.Diagnostics.ProcessStartInfo()
{
UseShellExecute = false,
CreateNoWindow = true,
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
FileName = "cmd.exe",
Arguments = "/C netstat -a -n |find \"5816\" |find \"ESTABLISHED\" /c",
RedirectStandardError = true,
RedirectStandardOutput = true
};
process.Start();
// Now read the value, parse to int and add 1 (from the original script)
int online = int.Parse(process.StandardOutput.ReadToEnd()) + 1;
process.WaitForExit();此代码启动cmd.exe可执行文件。使用/C参数,您可以为它提供要执行的命令
在Stackoverflow中进行简单的搜索,我得到了数百个可以帮助你的问题。
来源: How To: Execute command line in C#, get STD OUT results,Run Command Prompt Commands
https://stackoverflow.com/questions/36256114
复制相似问题