简体   繁体   English

bash 脚本返回状态 -13

[英]the bash scripts returns status -13

Scenario: Below are two scripts where a bash script is invoked by python script.场景:下面是两个脚本,其中 python 脚本调用了 bash 脚本。

test.py测试.py

import subprocess
p=subprocess.call(['bash','test.sh'])
f = open("demofile2.txt", "a")
f.write(p)
f.close()

test.sh测试.sh

echo "hello world"

observation: works fine when the test.py is executed directly.观察:直接执行 test.py 时工作正常。

issue: when I create demon under /service to run the file.问题:当我在 /service 下创建恶魔来运行文件时。 The value of 'p' (return of call) is -13. 'p'(调用返回)的值为 -13。

Note: The user:group for both script is root.注意:两个脚本的 user:group 都是 root。 I am using centos8我正在使用centos8

If anyone has same problem, the answer lies in the resolution of the path.如果有人有同样的问题,答案就在于路径的解决。

When I to execute the python script in the command line, it was able to locate the script.当我在命令行中执行 python 脚本时,它能够找到该脚本。 But when the demon tool (even systemd) runs the script it was not able to locate the bash script.但是当恶魔工具(甚至 systemd)运行脚本时,它无法找到 bash 脚本。 When I provided absolute path of the bash script(opt\test\test.sh) in the python script,it worked.当我在 python 脚本中提供 bash 脚本(opt\test\test.sh)的绝对路径时,它起作用了。

\opt\test\test.py \opt\test\test.py

import subprocess
p=subprocess.call(['bash','opt\test\test.sh'])
f = open("demofile2.txt", "a")
f.write(p)
f.close()

\opt\test\test.sh \opt\test\test.sh

echo "hello world"

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

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