我正在尝试制作一个在服务器上运行 newman 并保存报告的 python 脚本,但是当我运行此代码时,它显示“找不到文件”,当我在命令之前放置 nmp.cmd 的绝对路径时,npm 不会没看到纽曼。有谁知道如何让它发挥作用吗?
try:
process = subprocess.Popen(['newman', 'run', '<path to the collection>', '--export-collection','<path to the export file>'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(f"Newman started. PID: {process.pid}")
process.wait()
print(f"Command completed with return code {process.returncode}")
except Exception as e:
print(e)
使用 npm.cmd
try:
process = subprocess.Popen(['C:\\Program Files\\nodejs\\npm.cmd','newman', 'run', '<path to the collection>', '--export-collection','<path to the export file>'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(f"Newman started. PID: {process.pid}")
process.wait()
print(f"Command completed with return code {process.returncode}")
except Exception as e:
print(e)
示例一正确只需插入参数shell=True
try:
process = subprocess.Popen(['newman', 'run', '<path to the collection>', '--export-collection','<path to the export file>'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
print(f"Newman started. PID: {process.pid}")
process.wait()
print(f"Command completed with return code {process.returncode}")
except Exception as e:
print(e)