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

How to call a system command with flexibility on Windows

Hi everyone,
I have a hard time trying to call a system command with the following
capability on Windows:
- Redirection of stdout and stderr.
- Have the return code.

The documentation seems to say it's only possible on Unix, have I missed
something. Thx for your help.

Nicolas

Jul 18 '05 #1
4 1294
Nicolas Fleury wrote:

I have a hard time trying to call a system command with the following
capability on Windows:
- Redirection of stdout and stderr.
- Have the return code.

The documentation seems to say it's only possible on Unix, have I missed
something. Thx for your help.


It can be done on Windows, although at the very least you cannot redirect
stderr properly from the command line on Win98.... not sure about other
issues.

I'm pretty sure return codes are available with os.system() under Windows,
but I rarely use them and forget any relevant details.

-Peter
Jul 18 '05 #2
Peter Hansen wrote in message <40***************@engcorp.com>...
It can be done on Windows, although at the very least you cannot redirect
stderr properly from the command line on Win98.... not sure about other
issues.
Win98 is particularly bad:
os.system('dir') #output snipped
0 #return code os.system('foo') Bad command or file name
0

I'm pretty sure return codes are available with os.system() under Windows,
but I rarely use them and forget any relevant details.

--
Francis Avila
Jul 18 '05 #3
Nicolas Fleury wrote:
Hi everyone,
I have a hard time trying to call a system command with the
following capability on Windows:
- Redirection of stdout and stderr.
- Have the return code.

The documentation seems to say it's only possible on Unix, have I missed
something. Thx for your help.

Some, if not all of the popen functions on Windows will return the exit
code of the program when closing the last returned handle. I'm afraid I
have no time to check the docs or find sample code, but it does work :)

Mark.

Jul 18 '05 #4
On Thu, 2004-01-15 at 20:09, Mark Hammond wrote:
Some, if not all of the popen functions on Windows will return the exit
code of the program when closing the last returned handle. I'm afraid I
have no time to check the docs or find sample code, but it does work :)


I believe os.popen does on both cygwin and plain windows; e.g.,

cmd = 'some command'
stdout = os.popen(cmd)
print stdout.read()
exitCode = stdout.close()
if exitCode:
print '%s failed, this probably says why:\n%s' % (cmd, stdout)

Although I suppose spelling it "stdout" is misleading--doesn't popen
return stdout/stderr combined?

Cheers,

// m
Jul 18 '05 #5

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

Similar topics

5
by: Ayesha Ahsan | last post by:
Hi, I use Runtime.getRuntime().exec(command) to make my system call. For Windows based Dos, i add "cmd /c" before I type in my system call. So for example make the system call "dir": String...
2
by: gregpinero | last post by:
Hey everyone, I'm trying to call a system command "svnlook log \arms" from within python and process the results. However I'm having trouble getting the results of the command back into python....
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
2
by: AAguiar | last post by:
Thanks for your replies. Last week, I continued working with this problem. Trying to reproduce the error, I developed a short example and found that the problem is related to strong name dll. ...
14
by: AAguiar | last post by:
Thanks for your replies. Last week, I continued working with this problem. Trying to reproduce the error, I developed a short example and found that the problem is related to strong name dll. ...
10
by: kaci_tizi_ouzou2000 | last post by:
Greetings all. I am trying to make a system call as on WinXP, #include <stdlib.h> int main() { system( "ls -al"); }
3
by: 4.spam | last post by:
Hello. v8.2.1, Windows. I have a default installation on Windows where instance owner has administrative rights in the system. In this case user with only CREATE_EXTERNAL_ROUTINE authority and...
35
by: jleslie48 | last post by:
I've written a cgi program in C using the borland 5.5 free compiler, and it runs just fine on an Apache server. My only issue is if I issue some system calls the cgi suspends until the call...
12
by: Atropo | last post by:
Hi all. Having several strings how do i combine them to construct a command; lets say to run the date command. string str = "14/10/08 19:06:09"; strDD = str.substr(0,2); strMM =...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.