Knowledge map advanced must read: read how large-scale map data efficient storage and retrieval>>>
Recently, we encountered a script call problem in the company project. A python command-line tool started a zookeeper shell script using the subprocess module, and reported an error during execution: oserror: [errno 8] exec format error, as shown in the figure below:
At this point, I try to execute the shell script in the red box on the command line : is executed successfully, indicates that it is not a shell script problem
Then, I suspected that there was a problem with the permission of Python. I checked it online and said that I wanted to add a Python interpreter ( #)/ Usr/env/Python ), so I checked the content of the corresponding Python file: confirm that it contains / usr/env/python。
Then I worried about the issue of execution permission , so modified the executable permission of Python and shell scripts: but still did not solve the problem
chmod+xXXX.pychmod+x/etc/init.d/zookeeper
Finally, I suspect that there is something wrong with the shell script interpreter . At this time, I open the shell script (/etc/init. D/zookeeper ) and find that there is no / bin/sh
As we know, shell scripts can be executed in two ways:
1. sh XXX.sh
2. chmod +XXX.sh; ./ XXX.sh
For the second mode of operation, the script must contain a shell interpreter
As shown in the figure below, I added a shell interpreter (#)/ After that, the python script calls the shell script and does not report an error
So far, the problem has been solved
The debugging process is divided into three steps
1. Execute the shell script manually: see if the script itself has problems, and ignore the problem of calling the shell by python
2. Check the executable permissions: both shell and python scripts should ensure that the user has executable permissions. If you don’t feel at ease, use the script corresponding to Chmod + X
3. Check the interpreter of the script: because the script is an interpretive language (you need to specify an interpreter to execute line by line), it is not a compiled language (you don’t need to translate and interpret line by line after compiling). If there is no interpreter, the script may not be executable
Blogger: testing makes money
Motto: test to complete the original accumulation, invest to financial freedom
csdn: https://blog.csdn.net/ccgshigao
Blog Park: https://www.cnblogs.com/qa-freeroad/
51cto: https://blog.51cto.com/14900374
In this article, we share the blog “test makes money” (51CTO).
Similar Posts:
- Error reporting of importing tensorflow package from pycharm
- Groovy executes the script command shell command [Solved]
- Solve the Chinese display garbled code under centos7
- One of the ways to display no author, no date in SVN log
- Project interpreter not specified(eclipse+pydev)
- Error interpreter field is empty when installing pychar to create a new project. Run the python program
- Solve the GIT commit error and bypass the code check
- Linux shell script execution error: bad substitution [How to Solve]
- [Solved] Autosub error: ffmpeg: Executable not found on machine.
- Modify the script execution permission of PowerShell, and solve the problem of error reporting of commands executed by built-in terminals such as vscode (XX cannot recognize the name of cmdlets, functions, script files or runnable programs)