[英]Execute command in remote pc using PsExec - c#
我试图使用将在集线器/服务器PC上运行的控制台应用程序将远程PC设置为Selenium节点。
当程序在调试模式下运行时,我在“ errorMessage”中得到以下文本
The handle is invalid.
Connecting to 200.200.20.200:5555...
Couldn't access 200.200.20.200:5555
Connecting to 200.200.20.200:5555...
服务器在以下位置具有PsExec:D:\\ PSTools \\ PsExec.exe
服务器IP:100.100.10.100
远程IP:200.200.20.200
远程PC中的jar文件保存在:D:\\ Selenium \\ selenium-server-standalone.jar
要在远程PC中运行的命令是
D:\Selenium>java -jar selenium-server-standalone.jar -role node -hub http://100.100.10.100/grid/register
我在这里想念什么
private static void StartSeleniumNode()
{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.FileName = @"D:\PSTools\PsExec.exe";
p.StartInfo.Arguments = @"\\200.200.20.200:5555 -u xyz -p abc123 -i -w D:\Selenium java -jar selenium-server-standalone.jar -role node -hub http://100.100.10.100:4444/grid/register";
p.Start();
string output = p.StandardOutput.ReadToEnd();
string errormessage = p.StandardError.ReadToEnd();
p.WaitForExit();
}
您应该可以自己解决这个问题
您给了我们: p.StartInfo.Arguments = @"\\\\200.200.20.200"; \\\\what should go here
p.StartInfo.Arguments = @"\\\\200.200.20.200"; \\\\what should go here
好了,您有要运行的命令
java -jar selenium-server-standalone.jar -role node -hub http://100.100.10.100/grid/register
您知道要在其上运行它的PC。。您具有psexec来获取发送它所需的参数。
所以,它会像
D:\PSTools\PsExec.exe psexec \\remotepc -i -w D:\Selenium java -jar selenium-server-standalone.jar -role node -hub http://100.100.10.100/grid/register
尝试从命令行运行该命令,并在命令行正常运行时运行它。 您已经准备好进行编码了(让我们假设它是可行的。)
您的代码将是
p.StartInfo.FileName = @"D:\PSTools\PsExec.exe";
p.StartInfo.Arguments = @"\\remotepc -i -w D:\Selenium java -jar selenium-server-standalone.jar -role node -hub http://100.100.10.100/grid/register";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.