473,770 Members | 2,519 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

popen eating quotes?

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 example and not in the second.

C:\Temp>"c:\pro gram files\test\args " -vv abc
C:\Temp>echo -vv
-vv
C:\Temp>echo abc
abc

C:\Temp>"c:\pro gram files\test\args " -vv "abc"
C:\Temp>echo -vv
-vv
C:\Temp>echo "abc"
"abc"
from python, i'm having trouble getting the quotes around abc to work
import os
def run_args(arg): .... i, o = os.popen4('"c:/program files/test/args.bat" -vv %s' % arg)
.... print o.read()
.... run_args('abc') C:\python\pytho n23\lib\site-packages>echo -vv
-vv
C:\python\pytho n23\lib\site-packages>echo abc
abc
run_args('"abc" ')

'c:/program' is not recognized as an internal or external command,
operable program or batch file.
what is going on here? why does "abc" effect the uoted program name. does
anyone know how to fix this? how to pass a quoted arguments through to
popen? i need to do this because in my real code, i'm passing paths as
arguments and need them quoted.

i'm using python 2.3 on winxp.

thanks,

bryan
Jul 18 '05 #1
9 3412
This has been discussed before. One such thread that I participated in
was
http://groups.google.com/groups?hl=e...1%26filter%3D0
[apologies for the long URL, I don't know how to get a good memorable
URL for a google groups search]

This really is a cesspool on Windows, and the fault isn't Python's.
Python is just calling the Windows functions, which insist on behaving
badly compared to the Unix behavior.

unix bigot'ly yours,
jeff

Jul 18 '05 #2

"Jeff Epler" <je****@unpytho nic.net> wrote in message
news:ma******** *************** **********@pyth on.org...
This has been discussed before. One such thread that I participated in
was
http://groups.google.com/groups?hl=e...1%26filter%3D0 [apologies for the long URL, I don't know how to get a good memorable
URL for a google groups search]

This really is a cesspool on Windows, and the fault isn't Python's.
Python is just calling the Windows functions, which insist on behaving
badly compared to the Unix behavior.

unix bigot'ly yours,
jeff


thanks for the link, but it didn't help me solve my problem. i just read
many articles posted about popen and windows and there seems to be a
solution to this problem. i need to pass a path to a program using popen so
i can capture the output. since the path and/or file name can have spaces
in it, i need to quote it. what's the way to get around this issue? i saw
it mentioned in several places to try win32pipe.popen , but it had the same
problem as os.popen. so, is this something that cannot be done in python at
all with no work-around? is there another way besides using os.system or
os.popen?
import os
def run_args(arg): .... i, o = os.popen4('"c:/program files/test/args.bat" -vv %s' % arg)
.... print o.read()
.... run_args('"this is a very long path with spaces"')

'c:/program' is not recognized as an internal or external command,
operable program or batch file.

thanks,

bryan
Jul 18 '05 #3
Quoth Jeff Epler:
http://groups.google.com/groups?hl=e...1%26filter%3D0
[apologies for the long URL, I don't know how to get a good memorable
URL for a google groups search]


Not memorable, but at least shorter, is
<http://groups.google.c om/groups?threadm= 0000161b%40boss ar.com.pl>
In general all you need is the threadm or selm parameter, which
gives the message-id of the post in question; if memory serves,
threadm and selm differ in whether the resulting page shows the
rest of the thread.

(Ignore the selm in your URL above; it's inside the prev
parameter, which stores information about where you were before
arriving at the page the URL is actually for.)

It seems that Google also assigns an id to each thread; with
suitable poking around (see, e.g., the source for the page at the
above URL) you can locate a 'th' parameter which can be used in
place of the threadm/selm parameter if you wish to refer to the
thread as a whole. In your case that's
<http://groups.google.c om/groups?th=77576 209b6262476>
(As this illustrates, the resulting URL is often shorter than one
using the message-id.) The first ten messages in the thread
appear on the page obtained thus, with anchors, so you can refer
to them individually by appending '#link1', '#link2', etc. This
makes nice short URLs too (though I'm not certain that *which*
messages such anchors refer to is constant over time as the thread
grows).

All discovered empirically. Use at your own risk.

--
Steven Taschuk st******@telusp lanet.net
"Telekinesi s would be worth patenting." -- James Gleick

Jul 18 '05 #4
Bryan wrote in news:LOgXa.5780 8$o%2.28737@scc rnsc02:
import os
def run_args(arg): ... i, o = os.popen4('"c:/program files/test/args.bat" -vv %s' % arg)
... print o.read()
... run_args('"this is a very long path with spaces"') 'c:/program' is not recognized as an internal or external command,
operable program or batch file.


I just got the following working where os.getcwd() is returning:
'C:\\Documents and Settings\\Rob\\ Desktop'

def f():

.... i, o = os.popen4( "\"" + os.getcwd() + "\\aaa.bat\ "" )
.... print o.read()
.... i.close()
.... o.close()
....
If this dosen't help, then (sound of large hammer being removed
from a tool box) maybe this will:

def g(arg):
x = os.getcwd()
os.chdir( "c:/program files/test/" )
i, o = os.popen4( 'args.bat -vv %s' % arg )
os.chdir( x )
print o.read()
Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 18 '05 #5
"Rob Williscroft" <rt*@freenet.RE MOVE.co.uk> wrote in message
news:Xn******** *************** **********@195. 129.110.201...
Bryan wrote in news:LOgXa.5780 8$o%2.28737@scc rnsc02:
> import os
> def run_args(arg):

... i, o = os.popen4('"c:/program files/test/args.bat" -vv %s' % arg)
... print o.read()
...
> run_args('"this is a very long path with spaces"')

'c:/program' is not recognized as an internal or external command,
operable program or batch file.


I just got the following working where os.getcwd() is returning:
'C:\\Documents and Settings\\Rob\\ Desktop'

def f():

... i, o = os.popen4( "\"" + os.getcwd() + "\\aaa.bat\ "" )
... print o.read()
... i.close()
... o.close()
...
If this dosen't help, then (sound of large hammer being removed
from a tool box) maybe this will:

def g(arg):
x = os.getcwd()
os.chdir( "c:/program files/test/" )
i, o = os.popen4( 'args.bat -vv %s' % arg )
os.chdir( x )
print o.read()
Rob.
--
http://www.victim-prime.dsl.pipex.com/

rob,

thanks... this is exactly the solution i came up with too. it does remove
the path, but not the spaces in the file name. i _might_ be able to live
with this hack though.

the code i'm porting to python is from perl, and the perl code doesn't have
the popen issue.

@xxxoutput=`xxx -vv "$file"`;

now i won't be able show how cool python is :(

bryan
Jul 18 '05 #6
On Sun, 3 Aug 2003 17:45:00 -0600, Steven Taschuk wrote:
Not memorable, but at least shorter, is
<http://groups.google.c om/groups?threadm= 0000161b%40boss ar.com.pl>
In general all you need is the threadm or selm parameter, which
gives the message-id of the post in question; if memory serves,
threadm and selm differ in whether the resulting page shows the
rest of the thread.
Fortunately, the Message-Id: is available in the message itself (it's
part of every NNTP posting), so even without Google you theoretically
have complete information to give the Google Groups URL for any post:

<http://groups.google.c om/groups?threadm= MESSAGE-ID>

for threaded, or

<http://groups.google.c om/groups?selm=MES SAGE-ID>

for the message alone.
All discovered empirically. Use at your own risk.


Likewise.

--
\ Eccles: "I just saw the Earth through the clouds!" Lew: "Did |
`\ it look round?" Eccles: "Yes, but I don't think it saw me." |
_o__) -- The Goon Show, _Wings Over Dagenham_ |
Ben Finney <http://bignose.squidly .org/>
Jul 18 '05 #7
Hello Bryan,
run_args('"abc" ')

'c:/program' is not recognized as an internal or external command,
operable program or batch file.


Didn't check but maybe win32api.GetSho rtPath will help.
(Get Mark's excellent package from http://starship.python.net/crew/mhammond/)

HTH.
Miki
Jul 18 '05 #8
On Sun, 3 Aug 2003 17:45:00 -0600, Steven Taschuk
<st******@telus planet.net> wrote:
Quoth Jeff Epler:
http://groups.google.com/groups?hl=e...1%26filter%3D0
[apologies for the long URL, I don't know how to get a good memorable
URL for a google groups search]


Not memorable, but at least shorter, is
<http://groups.google.c om/groups?threadm= 0000161b%40boss ar.com.pl>
In general all you need is the threadm or selm parameter, which
gives the message-id of the post in question; if memory serves,
threadm and selm differ in whether the resulting page shows the
rest of the thread.

(Ignore the selm in your URL above; it's inside the prev
parameter, which stores information about where you were before
arriving at the page the URL is actually for.)

It seems that Google also assigns an id to each thread; with
suitable poking around (see, e.g., the source for the page at the
above URL) you can locate a 'th' parameter which can be used in
place of the threadm/selm parameter if you wish to refer to the
thread as a whole. In your case that's
<http://groups.google.c om/groups?th=77576 209b6262476>
(As this illustrates, the resulting URL is often shorter than one
using the message-id.) The first ten messages in the thread
appear on the page obtained thus, with anchors, so you can refer
to them individually by appending '#link1', '#link2', etc. This
makes nice short URLs too (though I'm not certain that *which*
messages such anchors refer to is constant over time as the thread
grows).

All discovered empirically. Use at your own risk.


If all you want is a short URL for posting, have a look at
http://tinyurl.com/

Jeff's *long* URL would then be: http://tinyurl.com/iy1q

--Christopher
Jul 18 '05 #9
craiggallagher
1 New Member
I came across this problem too - I got round it by adding the executable directory to the start of my path, then calling just the executable filename:

path = os.getenv("PATH ")
os.putenv("PATH ", r"C:\Program Files\Microsoft Visual Studio .NET\Common7\ID E;" + path)
vsCommand = 'devenv.com /build debug myproj.vcproj'
processHandles = popen2.popen4(v sCommand)
Apr 20 '06 #10

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

Similar topics

5
3750
by: Anders Dalvander | last post by:
os.popen does not work with parameters inside quotes, nor do os.popen. At least on Windows. import os cmd = '"c:\\command.exe" "parameter inside quotes"' os.popen4(cmd) Results in the following error message: 'c:\\command.exe" "parameter inside quotes' is not recognized as an
2
4320
by: Stuart McGraw | last post by:
When I run (Python 2.3.3) this script on a MS Windows 2000 machine: import os print "1st popen..." f = os.popen ("echo " + u"\u0054\u0045\u0053\u0054.txt") print f.read () print "2nd popen..." f = os.popen ("echo " + u"\u5927\u7530\u8061\u7f8e.txt") print f.read ()
10
2891
by: Nick Craig-Wood | last post by:
I'm trying to avoid using shell metacharacters in os.popen in a portable fashion. os.popen() only seems to take a string as the command which would need tricky quoting. os.popen2() can take a string or a list - the relevant code in Unix python (in popen2.py) being... def _run_child(self, cmd):
4
3231
by: agarwalpiyush | last post by:
Hello, I am going nuts with trying to get the following to work: This is what I intend to do: I have a line in /etc/syslog.conf which I need to delete based on ip-address provided to me in a variable. Forgetting that variable part for now .. this is what i want in the grep command: grep -suob "\*\.\* *...@172.23.62.12"
3
7850
by: Jesse | last post by:
Hi all, I have a problem using wget and Popen. I hope someone can help. -- Problem -- I want to use the command: wget -nv -O "dir/cpan.txt" "http://search.cpan.org" and capture all it's stdout+stderr. (Note that option -O requires 'dir' to be existing before wget is executed) Popen doesn't work, while os.system and shell do. Popen will give the error:
15
8726
by: Daniel Klein | last post by:
I'm trying to get popen to work on Windows. Here's a simplified example of what I'm trying to get working: I have a hw.c program as follows: #include <stdio.h> main() { printf ("Hello World!\n");
7
4934
by: skunkwerk | last post by:
Hi, i'm trying to call subprocess.popen on the 'rename' function in linux. When I run the command from the shell, like so: rename -vn 's/\.htm$/\.html/' *.htm it works fine... however when I try to do it in python like so: p = subprocess.Popen(,stdout=subprocess.PIPE,stderr=subprocess.PIPE) print p.communicate()
8
4215
by: clyfish | last post by:
In cmd, I can use find like this. C:\>netstat -an | find "445" TCP 0.0.0.0:445 0.0.0.0:0 LISTENING UDP 0.0.0.0:445 *:* C:\> And os.system is OK. TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
25
2793
by: Jeremy Banks | last post by:
Hi. I wondered if anyone knew the rationale behind the naming of the Popen class in the subprocess module. Popen sounds like the a suitable name for a function that created a subprocess, but the object itself is a subprocess, not a "popen". It seems that it would be more accurate to just name the class Subprocess, can anyone explain why this is not the case? Thank you.
0
10230
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10058
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.