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

os.popen() not executing command on windows xp

nic
On my system (WinXP) typing the following line into command
prompt(cmd.exe) successfully scans the file test1.txt:
"c:\Program Files\Grisoft\AVG Free\avgscan.exe" "c:\program
files\temp1\test1.txt"

Yet the python script:
import os
a = os.popen('"c:\Program Files\Grisoft\AVG Free\avgscan.exe"
"c:\program files\temp1\test1.txt"')
print a.read()

Returns a blank line, and I doesn't scan the file. (Note I've used
os.popen() successfully on my system in other situations like:
os.popen('taskkill /F /IM taskname.exe')).

I have a feeling my avgscan example shown above not working has
something to do with calling a 3rd party software program (avgscan.exe)
through popen, but I don't know why this won't work, when manually
typing it in the command line does?

Jan 11 '07 #1
5 4311
At Thursday 11/1/2007 06:42, nic wrote:
>a = os.popen('"c:\Program Files\Grisoft\AVG Free\avgscan.exe"
"c:\program files\temp1\test1.txt"')
Your string contains backquotes, and they have to be escaped.
Either use a raw string: os.popen(r'"c:\Program...) or double all
backquotes: os.popen('"c:\\Program...)
--
Gabriel Genellina
Softlab SRL


__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Jan 11 '07 #2
import os
a = os.popen('"c:\Program Files\Grisoft\AVG Free\avgscan.exe"
"c:\program files\temp1\test1.txt"')
print a.read()
use raw strings

e.g., instead of '"c:...\avgscan...'
use r'"c:...\avgscan...'

http://www.ferg.org/projects/python_...ontents_item_2

Jan 11 '07 #3
nic
Justin Ezequiel wrote:
import os
a = os.popen('"c:\Program Files\Grisoft\AVG Free\avgscan.exe"
"c:\program files\temp1\test1.txt"')
print a.read()

use raw strings

e.g., instead of '"c:...\avgscan...'
use r'"c:...\avgscan...'

http://www.ferg.org/projects/python_...ontents_item_2
Sorry I initally had retyped the code to replace some variables to make
it more clear, I already had them as raw strings:

import os
pstr = r'"c:\Program Files\Grisoft\AVG Free\avgscan.exe" "c:\program
files\temp1\test1.txt"'
a = os.popen(pstr)
print a.read()

I've confirmed the string I'm inputting to os.popen is EXACTLY the same
as the one I can successfully execute manually in command prompt, so
when I go:
print pstr, it yields:
"c:\Program Files\Grisoft\AVG Free\avgscan.exe" "c:\program
files\temp1\test1.txt"

The problem remains popen won't execute this line as it does when
inputted manually to command prompt.

Jan 11 '07 #4
nic
It appears os.popen() doesn't like full windows paths with spaces (e.g.
"c:/program files") so I'm going to use the subprocess module.

Jan 11 '07 #5
At Thursday 11/1/2007 14:09, nic wrote:
>import os
pstr = r'"c:\Program Files\Grisoft\AVG Free\avgscan.exe" "c:\program
files\temp1\test1.txt"'
a = os.popen(pstr)
print a.read()

I've confirmed the string I'm inputting to os.popen is EXACTLY the same
as the one I can successfully execute manually in command prompt, so
when I go:
print pstr, it yields:
"c:\Program Files\Grisoft\AVG Free\avgscan.exe" "c:\program
files\temp1\test1.txt"

The problem remains popen won't execute this line as it does when
inputted manually to command prompt.
I have AVG so I tried this example. That's not the problem. popen
works ok, avgscan is executed. But the avgscan program does *not* use
stdout nor stderr to write to the console, so popen can't capture its output.
You can confirm this at the command prompt:

"c:\Program Files\Grisoft\AVG Free\avgscan.exe" "c:\program
files\temp1\test1.txt" >output.txt 2>&1

You will see the usual progress messages from avgscan *on screen*,
and when you type output.txt, it's empty. avgscan appears to write
directly to the console.
You may use the /REPORT option; avgscan /? for details.
--
Gabriel Genellina
Softlab SRL


__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Jan 12 '07 #6

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

Similar topics

1
by: Jonathan Hudgins | last post by:
When I try setting the bufsize on popen on windows I get the following error: output = os.popen( "ls", 'r', 1 ) ValueError: popen() arg 3 must be -1 The same is true for popen2, popen3 and...
10
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...
2
by: Your Friend | last post by:
Hello All, I'm relatively new to Python programming but have been working on this problem for a little bit now ... I initially began writing UNIX scripts in Python and thought it was the...
2
by: Ernesto | last post by:
I'm trying to use Popen to do some command line work Windows XP style. I have devcon.exe which I would use on a Windows command line like so: devcon disable...
2
by: hubritic | last post by:
I am trying to set off commands on Windows 2003 from python. Specifically, I am trying to use diskpart with a script file (pointed to with path). cmd = p = Popen(cmd, shell=True) The script...
3
by: Doru Moisa | last post by:
Hello, How can I capture the output of a long runnning process which I open with popen() ? I tried reading line by line, char by char, but the result always comes when the process finishes. (I...
15
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...
8
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....
0
by: Eric Carlson | last post by:
Werner F. Bruhin wrote: Try: p = subprocess.Popen(command, shell=True, tdin=subprocess.PIPE, stdout=subprocess.PIPE) was working on xp and osx
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...
0
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...

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.