0

i can't find solution for this problem code below:

import subprocess
subprocess.call(['./eu_presun.sh'])

shell script is in the same dir as main.py i will use python then i want use this shell script I'm getting this error.

Traceback (most recent call last):
  File "~/_main.py", line 304, in <module>
    subprocess.call(['sh eu_presun.sh'])
  File "/usr/lib/python3.8/subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: './eu_presun.sh'
Lunamax
  • 13
  • 5
  • to add: python script works perfectly and shell script works perfectly too also separately `-rwxr-xr-x 1 ################### eu_presun.sh` – Lunamax Feb 25 '20 at 21:04
  • It may work separately *when you call it from a shell*, but if it fails without a shell from Python, it'll fail in plenty of other situations too. Fix the real problem, don't just work around it by explicitly starting a shell. – Charles Duffy Feb 25 '20 at 21:21
  • To give you an example, try running `echo . | xargs -n 1 ./eu_presun.sh` -- if there's a problem that means the OS can't successfully run `eu_presun.sh` as an executable, that'll fail too. (If it *doesn't* fail, then that tells us that our problem was only about your `os.getcwd()` in Python not being the same directory the shell script is actually located in). – Charles Duffy Feb 25 '20 at 21:22
  • If it *is* only the directory mismatch, then see [running a file in the same directory as the invoking Python module or script](https://stackoverflow.com/questions/41623800/running-a-file-in-the-same-directory-as-the-invoking-python-module-or-script). – Charles Duffy Feb 25 '20 at 21:24
  • 1
    I don't understand how this traceback is possible. Why does it say `~/_main.py` instead of `/home/you/_main.py`? How did it get from `'sh eu_presun.sh'` on the third line to `'./eu_presun.sh'` on the last? – that other guy Feb 25 '20 at 21:26

1 Answers1

-1

okey im bit tired answer is

subprocess.call(['./eu_presun.sh']**,shell=True**)

also i have problems with this address and i had to add full path

Lunamax
  • 13
  • 5
  • That's only an answer if your script isn't executable. Since you're showing that the `+x` permissions are correct, maybe it doesn't have a valid shebang (first line like `#!/bin/sh` or `#!/usr/bin/env bash`, as appropriate for whichever shell it's actually written to run with)? It's also conceivable that there are other OS settings/permissions impacting execution (a `noexec` mount point, or SELinux policy, or so forth -- though all those much rarer / less likely than just having an invalid shebang). – Charles Duffy Feb 25 '20 at 21:17
  • 1
    Point being, scripts that your operating system can successfully invoke as executable don't need `shell=True` to run. The only time when `shell=True` would "fix" anything is if the permissions or the shebang are broken, because some shells (not all of them!) fall back to trying to run something in another copy of the selfsame interpreter if the OS says that `execve()` (the right/proper way to start an external process) doesn't work. – Charles Duffy Feb 25 '20 at 21:17