[program-l] Re: Python 2.7.9: passing arguements to subprocess

  • From: Yuma Antoine Decaux <jamyad7@xxxxxxxxx>
  • To: "program-l@xxxxxxxxxxxxx" <program-l@xxxxxxxxxxxxx>
  • Date: Fri, 3 Apr 2015 01:01:41 +1000

If you check the subprocess module, you will see that they contain stderr() and
stdout, so use call([whatever command and options](), stderr=pipe,
stdout=pipe). Double check as i’m typing by memory

Cheers,



Yuma Antoine Decaux
"Light has no value without darkness"
Mob: +61 410732547
Skype: Shainobi1
twitter: http://www.twitter.com/triple7





On 2/04/2015, at 11:42 pm, Pranav Lal <pranav.lal@xxxxxxxxx> wrote:

Hi Yuma,

The arguments to the call are dynamic which is why I am populating a list.
Moreover, I wanted to use the check_call routine because I want to catch any
errors that may occur. Can I catch errors using call or popen?

Pranav

From: program-l-bounce@xxxxxxxxxxxxx [mailto:program-l-bounce@xxxxxxxxxxxxx]
On Behalf Of Yuma Antoine Decaux
Sent: Thursday, April 02, 2015 11:29 AM
To: program-l@xxxxxxxxxxxxx
Subject: [program-l] Re: Python 2.7.9: passing arguements to subprocess

Hi,

Just put your first argument in pOpen() or call() in a list such as:
call([‘command’, ‘option’, ‘argument’, ‘…’], stderr, stdout, shell= whatever)


Cheers



Yuma Antoine Decaux
"Light has no value without darkness"
Mob: +61 410732547
Skype: Shainobi1
twitter: http://www.twitter.com/triple7 <http://www.twitter.com/triple7>





On 2/04/2015, at 11:48 am, Pranav Lal <pranav.lal@xxxxxxxxx
<mailto:pranav.lal@xxxxxxxxx>> wrote:

Hi all,

I need to execute an external program from my python script which is running
on
windows 7.
The commandline of the program is below.
convert img-150330141312.pdf -auto-level -compress none ocr.tiff

How do I use subprocess to do this? I have tried the below code and it is
failing by stating that -auto-level is an invalid parameter.

Note:
The convert.exe utility is a part of the image magic program.

def convertPDFImage(fpn,tempPath):
ocrOutputName=os.path.join(tempPath, 'ocr.tif')
cmList=[]
cmList.append('convert')
cmList.append(fpn)
cmList.append("-auto-level")
cmList.append("-compress none")
cmList.append(ocrOutputName)


try:
subprocess.check_call(cmList)

except CalledProcessError as e:
print(e.returncode)
ocrOutputName='error'
return ocrOutputName

Pranav

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
<mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]>
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx <mailto:program-l-request@xxxxxxxxxxxxx>
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
<mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]>
** or send a message, to
** program-l-request@xxxxxxxxxxxxx <mailto:program-l-request@xxxxxxxxxxxxx>
with the Subject:- faq

Other related posts: