#πŸ”’ Pass argument to bash script and run it from python

8 messages Β· Page 1 of 1 (latest)

tardy swift
#

Hi
I am trying to write a script to run a bash script that has the absolute path to a file passed to it. I am using subproces to run the bash script and all files except for the mkv files are in the same folder

root = "/mnt/Anime/Series/-Akuyaku Reijou Level 99/"
#  Scan directory for .mkv files
for root, directory, files in os.walk(root, topdown=True):
    directory.sort()
    for filename in sorted(files):
        if filename.endswith(".mkv"):
            full_path = os.path.join(root, filename)
            print(f"{full_path}")
            subprocess.call(["./file-rename.sh", f"{full_path}" ])

Unfortunately most of the example on the internet deal with passing commands so I am not even sure the way I doing it is possible.

Here is the output

madzi@Network-Rage:~/dev/linx-scripting/bash-scripts/bulk-rename$ python3 file-rename.py
/mnt/Anime/Series/-Akuyaku Reijou Level 99/[ASW] Akuyaku Reijou Level 99 - 01 [1080p HEVC].mkv
Traceback (most recent call last):
  File "/home/madzi/dev/linx-scripting/bash-scripts/bulk-rename/file-rename.py", line 15, in <module>
    subprocess.call(["./file-rename.sh", f"{full_path}" ])
  File "/usr/lib/python3.11/subprocess.py", line 389, in call
    with Popen(*popenargs, **kwargs) as p:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.11/subprocess.py", line 1901, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: './file-rename.sh'

Any help would be appreciated.

loud cipherBOT
#

@tardy swift

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

jovial parcel
#

where is file-rename.sh in relation to the python script

tardy swift
#

In the same directory. Only the media files are in another directory.

jovial parcel
#

it can't find the script for some reason

tardy swift
#

I've figured it out, I'm such an idiot. I used the wrong name in the script.

loud cipherBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.