473,320 Members | 2,112 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,320 software developers and data experts.

execv putting quotes around arguments

I'm running into a problem when I try to run commands with os.execv. It
seems to be putting quotation marks around each element of the list
passed as its second argument. This is fine for the most part, but if
the argument has a space in it, getopt (in the command being called)
will read the entire quoted string as the argument and generally fail.

Here's an example:

Python 2.2.2 (#1, Jan 30 2003, 21:26:22)
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-112)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import os
arg0='/bin/ls'
arg1='-l foo'
args=[arg0]+[arg1]
os.execv(arg0, args)

/bin/ls: invalid option --
Try `/bin/ls --help' for more information.

This can be worked around by breaking '-l foo' into two seperate
elements ('-l' and 'foo'), but that's not always intuitive. Anyone know
why those quotes are there, and if there's a way to make them go away?
I'm stuck with execv, since this is part of a larger project for which
I'm creating a module, and modifying that portion to use os.popen,
os.system, or something similar isn't an option.

Mike Vieths

Jul 18 '05 #1
1 3503
In article <40***********************@newsreader.visi.com>,
Mike Vieths <fo*****@yahoo.com> wrote:
I'm running into a problem when I try to run commands with os.execv. It
seems to be putting quotation marks around each element of the list
passed as its second argument. This is fine for the most part, but if
the argument has a space in it, getopt (in the command being called)
will read the entire quoted string as the argument and generally fail. .... This can be worked around by breaking '-l foo' into two seperate
elements ('-l' and 'foo'), but that's not always intuitive. Anyone know
why those quotes are there, and if there's a way to make them go away?
I'm stuck with execv, since this is part of a larger project for which
I'm creating a module, and modifying that portion to use os.popen,
os.system, or something similar isn't an option.


os.system(cmdline) is about the same as os.fork()
followed by os.execv('/bin/sh', ['sh', '-c', cmdline])

The way execv works is generally a strong advantage,
because it doesn't automatically run the shell over
its parameters (it doesn't `add quotes', it just
doesn't need them), and that shell step opens you
up to all kinds of unexpected possibilities if you
don't positively know what's going into the command
line. But if you want the shell, you can have it -
just invoke it.

Donn Cave, do**@u.washington.edu
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Bryan | last post by:
i have a batch file that contains these two lines: -- args.bat echo %1 echo %2 when i run args.bat from the command line it works correctly... notice that abc has quotes in the first...
0
by: Elmar Krieger | last post by:
Hi! The _spawnvp function expects the command line arguments as a NULL terminated list of char * pointers, hence there is no need to enclose filenames with quotes if they contain spaces....
4
by: (PeteCresswell) | last post by:
Is his just a flat-out "No-No" or is there some workaround when it comes time for SQL searches and DAO.FindFirsts against fields containing same? I can see maybe wrapping the value searched for...
3
by: Douglas Dillon | last post by:
I am trying to use tiffcp to reconfigure tif files (if they are tiled) to nontiled so I can use existing code to handle them. However, I am having issues providing the arguments. The app is run...
7
by: WALDO | last post by:
I wrote a console application that basically consumes arguments and starts other command line apps via System.Process. Let's call it XCompile for now. I wrote a Visual basic add-in that does pretty...
3
by: martin paul | last post by:
Sir please consider the following.... I would like to copy contents from one file (mart1.c) to another file (mart2.c) using execv() function (using command line arguments)..... The command...
2
by: drew007 | last post by:
Hi all I am looking to drop data into a table for export to a csv file for example see below. DoCmd.RunSQL "SELECT Temp11.RowNum As RowNum, " &_ "Replace(Temp11.studEnrolment1,',','') AS...
3
by: CMorgan | last post by:
Hi everybody, I am experiencing an annoying problem with fork() and execv(). In my program I need to launch the "pppd" from a thread, so, I create a new process with fork and then in the child...
2
Motoma
by: Motoma | last post by:
Hello everyone, I am having a tiny problem putting together a small script. I tried throwing together a multi-threaded ping utility, but the threads are not behaving the way I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.