RevolverOshawott
RevolverOshawott

Reputation: 101

How to run a Bash Script file in Python with arguments

I am looking to run the following bash script with python:

sed -n -e '/SCN/,/^\s*$/p' $@ > Junction-Links.txt

The bash script is saved as ext-jun-links.sh and I want to run it using Python to pass a file name in place of the $@.

I am currently trying to use the below code to do so:

import subprocess
from subprocess import call
    
subprocess.run(["./ext-jun-links.sh","NETL1405.TXT"], shell=True)

However, this gives me the error below:

'ext-jun-links.sh' is not recognized as an internal or external command, operable program or batch file.

Is there a way to solve this error? The bash file runs fine when using PowerShell with the following code, so that's not the issue:

bash ext-jun-links.sh 'NETL1405.TXT'

Upvotes: 0

Views: 129

Answers (1)

Max Turchin
Max Turchin

Reputation: 26

I think it's cus' you're trying to execute a bash script via PowerShell.

bash ext-jun-links.sh 'NETL1405.TXT'

This works, because you're feeding ext-jun-links.sh and 'NETL1405.TXT' as params to bash.

try:

subprocess.run(["bash", "./ext-jun-links.sh","NETL1405.TXT"], shell=True)

Upvotes: 1

Related Questions