473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 2684
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: rkoida | last post by:
Hello evryone I am a newbie to python. I have a makefile which i can compile in UNIX/LINUX, But i I am planning to write a python script which actually does what my MAKEFILE does. The make file...
3
by: Earl Eiland | last post by:
The command string consists of "filename.exe instruction1 instruction2 ...." It works in subprocess, but in process, returns the error "can't find the file instruction1". How do I pass command...
5
by: Chris Hieronymus | last post by:
Hi, I have a bunch of x-y data contained in an array. I would like to plot the data using an external program (psxy in GMT). The plotting program takes x-y couples as standard input. ...
16
by: John Salerno | last post by:
Here's my new project: I want to write a little script that I can type at the terminal like this: $ scriptname package1 where scriptname is my module name and any subsequent arguments are the...
6
by: =?iso-8859-1?q?Luis_M._Gonz=E1lez?= | last post by:
Please forgive me if what I'm asking is non sense... I created a little program to authomate the creation of the "setup.py" script for py2exe. It simply prompts for the main executable script...
3
by: CSUIDL PROGRAMMEr | last post by:
hi folks I am new to python. I have a module does call a os.command(cmd) where cmd is a rpm command. Instead of using os.command and getting the results on command line , i would like to dump the...
2
by: Jim | last post by:
Hello, I need a program that will traverse a directory tree to ensure that there are unix-style line endings on every file in that tree that is a text file. To tell text files from others I...
9
by: Phoe6 | last post by:
Hi all, Consider this scenario, where in I need to use subprocess to execute a command like 'ping 127.0.0.1' which will have a continuous non- terminating output in Linux. # code # This...
3
by: Shoryuken | last post by:
I'm new to Python, so my question may sounds naive. Here is it. I have a text file like this: www.a.com www.b.com www.c.com .... I want to read one line from this file at a time, which I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.