473,397 Members | 1,950 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,397 software developers and data experts.

bug in os.system?

The following code fails (pythonbugtest.exe takes one parameter, a
string):

import os
result = os.system('"pythonbugtest.exe" "test"')
assert(result == 0)

The error message is:

'pythonbugtest.exe" "test' is not recognized as an internal or external
command, operable program or batch file.
Traceback (most recent call last):
File "C:\Nick\!My Programs\Python\bugtest\python1.py", line 8, in ?
assert(result == 0)
AssertionError
If I remove the quote marks around "pythonbugtest.exe" or "test", it
works fine. But sometimes I need those quote marks, if e.g. there are
spaces in filenames.

I think this is a bug?

I'm running Python 2.4.1 on Windows XP Pro.

Oct 18 '05 #1
5 2016
What happens when you try it without the single quotes?
result = os.system("pythonbugtest.exe" "test")

Oct 18 '05 #2
wj******@gmail.com wrote:
What happens when you try it without the single quotes?
result = os.system("pythonbugtest.exe" "test")

That would be equivalent to

result = os.system("pythonbugtest.exetest")

which almost certainly won't do anything useful.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Oct 18 '05 #3
ni***********@yahoo.com wrote:
The following code fails (pythonbugtest.exe takes one parameter, a
string):

import os
result = os.system('"pythonbugtest.exe" "test"')
assert(result == 0)

The error message is:

'pythonbugtest.exe" "test' is not recognized as an internal or external
command, operable program or batch file.
Traceback (most recent call last):
File "C:\Nick\!My Programs\Python\bugtest\python1.py", line 8, in ?
assert(result == 0)
AssertionError

If I remove the quote marks around "pythonbugtest.exe" or "test", it
works fine. But sometimes I need those quote marks, if e.g. there are
spaces in filenames.

I think this is a bug?


yup, but unfortunately, it's a bug at the windows level, not in Python. from what
I can tell, the problem is that cmd.exe cannot parse the command string it's given
by the C-level system() call.

possible workarounds:

1. get rid of the quotes around the command name:

result = os.system('pythonbugtest.exe "test"')

2. add an extra quote (!) before the quoted command name:

result = os.system('""pythonbugtest.exe" "test"')

3. use os.spawn or the subprocess module instead.

</F>

Oct 18 '05 #4
OK, I give up. Why does workaround #2 work?

Also, I didn't realize this before, but when you call os.spawnv, the
argument list you pass starts with the name of the executable you're
calling! When you call a program from cmd.exe, that program name is
the first parameter automatically. But with spawnv, you do that
manually!

Anyway, thanks for your help!

Oct 18 '05 #5

ni***********@yahoo.com wrote:
OK, I give up. Why does workaround #2 work?
Well, there was a time when the cmd prompt treated all
spaces as delimiters, so
cd My Documents
would fail. Nowadays you can do that successfully and even
cd My Documents\My Pictures
works.

In the old days, if a directory had a space, you had to
enclose it in quotes
cd "My Documents"
But you didn't actually need to include the trailing quote,
so you could get away with
cd "My Documents
I'm sure if you looked it up, Microsoft would say

This behaviour is by design.


Also, I didn't realize this before, but when you call os.spawnv, the
argument list you pass starts with the name of the executable you're
calling! When you call a program from cmd.exe, that program name is
the first parameter automatically. But with spawnv, you do that
manually!

Anyway, thanks for your help!


Oct 19 '05 #6

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

Similar topics

3
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in...
2
by: Scott | last post by:
Not sure if this is the right place to post this or not, but I am in the process of trying to find a Web Hosting/Isp Billing system that is reasonable in price and uses Access or SQL Server for a...
0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
5
by: laks | last post by:
Hi I have the following xsl stmt. <xsl:for-each select="JOB_POSTINGS/JOB_POSTING \"> <xsl:sort select="JOB_TITLE" order="ascending"/> This works fine when I use it. But when using multiple...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
1
by: Sky | last post by:
Yesterday I was told that GetType(string) should not just be with a Type, but be Type, AssemblyName. Fair enough, get the reason. (Finally!). As long as it doesn't cause tech support problems...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
1
by: mfunkmann | last post by:
Hi, I recently got an error and I don't know how to fix it: Error 1 'System.Data.DataColumn' does not contain a definition for 'Windows' C:\c#\CsharpPRO\Form1.Designer.cs 304 77 CsharpPRO I...
2
by: =?Utf-8?B?TmF0aGFuIFdpZWdtYW4=?= | last post by:
Hi, I am wondering why the .NET Framework is quite different from Win32 API when it comes to displaying system modal message boxes. Consider the four following types of system modal message...
3
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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,...
0
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...

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.