468,537 Members | 1,555 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,537 developers. It's quick & easy.

command line arguments using subprocess

Jim
Hello,

I'm trying to use subprocess to drive a Perl script. I'm having some
trouble getting it to spot the command line arguments. Basically, if
I call subprocess(args).wait() where args has a second item, I can't
convince the Perl script to see it. Below is a pretty small example.
If someone could get me unstuck, I'd appreciate it. (Python 2.4.4c1,
if that helps.)

Thanks,
Jim
.................. /home/ftpmaint/test.pl................
#!/usr/bin/env perl
print "\$0 is -->$0<--\n";
print "\$ARGV[0] is -->$ARGV[0]<--\n";

die "usage: $0 PKGNAME\n" unless @ARGV == 1;
................/home/ftpmaint/subtest.py.................
import os,subprocess

args=['/home/ftpmaint/test.pl','a']
p=subprocess.Popen(args,shell=True,stdout=subproce ss.PIPE,stderr=subprocess.PIPE,cwd=os.getcwd())
retCode=p.wait()
print "retCode=",retCode
print "stdout>>",p.stdout.read()
print "stderr>>",p.stderr.read()
............ some command line work ..............
ftpmaint@millstone:~$ ./test.pl
$0 is --./test.pl--
$ARGV[0] is --><--
usage: ./test.pl PKGNAME

ftpmaint@millstone:~$ ./test.pl a
$0 is --./test.pl--
$ARGV[0] is -->a<--

ftpmaint@millstone:~$ python subtest.py
retCode= 255
stdout= $0 is --/home/ftpmaint/test.pl--
$ARGV[0] is --><--

Mar 14 '07 #1
1 2478
En Wed, 14 Mar 2007 16:51:04 -0300, Jim <jh*******@smcvt.eduescribió:
I'm trying to use subprocess to drive a Perl script. I'm having some
trouble getting it to spot the command line arguments. Basically, if
I call subprocess(args).wait() where args has a second item, I can't
convince the Perl script to see it. Below is a pretty small example.
If someone could get me unstuck, I'd appreciate it. (Python 2.4.4c1,
if that helps.)
args=['/home/ftpmaint/test.pl','a']
p=subprocess.Popen(args,shell=True,stdout=subproce ss.PIPE,stderr=subprocess.PIPE,cwd=os.getcwd())
Try with 'perl' explicitely as first argument, or without shell=True; if
cwd is the current dir, there is no need to include it.

--
Gabriel Genellina

Mar 15 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Chris Hieronymus | last post: by
16 posts views Thread by John Salerno | last post: by
6 posts views Thread by =?iso-8859-1?q?Luis_M._Gonz=E1lez?= | last post: by
3 posts views Thread by CSUIDL PROGRAMMEr | last post: by
9 posts views Thread by Phoe6 | last post: by
3 posts views Thread by Shoryuken | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.