我可以像这样
从命令提示符运行批处理文件PsExec.exe \\remoteMachine "C:\Users\admin\test.bat"
我正在尝试使用python
调用相同的上述命令remoteCommand = r'C:\Users\username\test.bat'
argList = ["PsExec.exe", remoteCommand]
out = subprocess.check_output(argList)
print "Output: ", out
但它会抛出如下所示的错误
The system cannot find the file specified.
PsExec could not start C:\Users\admin\test.bat:
.
.<Stacktrace present here>
.
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['PsExec.exe', 'C:\\Users\\admin\\test.bat']' returned non-zero exit status 2
答案 0 :(得分:0)
如果您所做的只是在远程计算机上运行批处理文件,则可以使用WMI而不是PSExec:
connection = wmi.WMI(ip, user='username', password='password')
startup = connection.Win32_ProcessStartup.new(ShowWindow=1)
connection.Win32_Process.Create(CommandLine=batcmd, ProcessStartupInformation=startup)
其中&#34; batcmd&#34;是远程计算机上批处理文件的完整本地路径(例如 - &#34; C:\\ directory \\ something.bat&#34;)。
答案 1 :(得分:0)
在您的参数列表中,您没有指明您正在呼叫的远程计算机。也许将你的args列表更改为:
argList = ["PsExec.exe", "\\\\remotemachine", remoteCommand]