简体   繁体   English

从Python Shell运行Python脚本

[英]Running Python script from Python shell

In a batch file residing in a remote desktop I have simply written "python jwRelay.py" 在驻留在远程桌面中的批处理文件中,我仅编写了“ python jwRelay.py”

I want to run the batch file using psexec using the following command: 我想使用以下命令使用psexec运行批处理文件:

psexec -s -i 2 \\135.20.230.160 -u administrator -p force cmd.exe /c "C:\Users\Administrator\Desktop\jwRelayCDV16\SampleCode\Python\relay.bat"

The issue is when I run the above command the command prompt in the remote machine quickly pops up and closes (I can see through mstsc). 问题是,当我运行上述命令时,远程计算机中的命令提示符迅速弹出并关闭(我可以通过mstsc看到)。 How can I keep the command prompt open if I want to debug the code remotely? 如果要远程调试代码,如何保持命令提示符打开?

In my laptop after running the above command I get this: 在运行上述命令后,在我的笔记本电脑中得到以下信息:

PsExec v2.11 - Execute processes remotely PsExec v2.11-远程执行进程
Copyright (C) 2001-2014 Mark Russinovich 版权所有(C)2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com Sysinternals-www.sysinternals.com

cmd.exe exited on 135.24.237.167 with error code 2. cmd.exe在135.24.237.167退出,错误代码为2。

Is there any other alternative than running the script jwRelay.py in interactive mode in the remote machine? 除了在远程计算机上以交互方式运行脚本jwRelay.py之外,还有其他选择吗?

Python 2 Python 2

execfile("./filename") 

Python 3 Python 3

exec(open("./filename").read())

There are probably also several ways to execute code and specific commands, using Python 2 commands or better for both subprocess which replaced it. 可能还有几种执行代码和特定命令的方法,使用Python 2 commands或更好的方法替换两个替换它的subprocess Off the top of my head there are [ commands|subprocess ] .getoutput , subprocess.Popen , subprocess.call , etc. 把我的头顶部有[ commands|subprocess ] .getoutputsubprocess.Popensubprocess.call等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM