RSS Amplifier

Rida Ayed · Jul 10, 2024

Call a bash script with arguments in python

0
Sign in to vote or save

This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.

/tmp/foo.py arguments = " " . join([ "foo" , "bar" ]) cmd = "foo.sh" subprocess . run([ '/bin/env' , cmd] + arguments) /tmp/foo.sh #!/bin/sh for arg in " $@ " ; do echo $arg done Now calling python foo.py calls foo.sh with arguments . Mind possible offtopic tasks like chmod +x , permissions etc. Source

/tmp/foo.py
arguments=" ".join(["foo", "bar"])
cmd="foo.sh"
subprocess.run(['/bin/env', cmd]+arguments)
/tmp/foo.sh
#!/bin/sh
for arg in "$@"; do
    echo $arg
done

Now calling python foo.py calls foo.sh with arguments.

Mind possible offtopic tasks like chmod +x, permissions etc.

Source

Read on /posts/call-bash-script-with-arguments-in-python/

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.