简体   繁体   中英

Difficulty executing a shell script from a python script

When I run a shell script in terminal it works as I want it to In terminal when I type: ./hello.sh pdflatex runs and the file compiles. It works perfectly. pdflatex creates a pdf file and it's all good.

I have a python script in the same directory as the shell script. When I run that script with a call to the shell script nothing happens

The code does not error out

I've looked through the forums, but this specific question is not addressed

The shell script called hello.sh contains:

#! /bin/bash
pdflatex n1.tex
import subprocess
subprocess.Popen(['/bin/bash', './hello.sh'],shell=True)

All I want to happen is that when I run this python script it executes the shell script and the other program pdflatex creates the pdf document

Try the following:

import subprocess
subprocess.run(['/bin/bash', './hello.sh'])

Or alternatively

import subprocess
subprocess.run(['./hello.sh'])

Or even

import subprocess
subprocess.run(['pdflatex', 'n1.tex'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM