简体   繁体   English

如何使用python脚本实现工人?

[英]how to implement workers with python script?

I am trying to implement a worker external bash script in my python script , but when I try to run it . 我试图在python脚本中实现一个worker外部bash脚本,但是当我尝试运行它时。 I got the error of /bin/sh: 1: worker.sh: not found , but my bash script it is in the same folder as my python script . 我收到了/bin/sh: 1: worker.sh: not found的错误/bin/sh: 1: worker.sh: not found但我的bash脚本与python脚本位于同一文件夹中。

├── tool.py
├── unix.sh
└── worker.sh
#!/usr/bin/python
import subprocess
subprocess.call('worker.sh', shell=True)
#!/bin/bash
echo "worker running"

Should be: 应该:

subprocess.call('./worker.sh', shell=True)

Using subprocess.call is similar to typing the command into a bash window. 使用subprocess.call类似于在bash窗口中键入命令。 So you either need to define the path to worker.sh (or add it to your path). 因此,您需要定义worker.sh的路径(或将其添加到您的路径中)。

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

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