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

How to know if a system command doesn't exist?

Hi,
How can I know if a system command doesn't exist? All the ways I have
tried behave like if the system command was existing but returning one.
I don't want to sound provocative, but open in Perl returns an error
in a command doesn't exist, so I'm sure we could have an exception in
the same case for popen in Python?

Thx and Regards,

Nicolas

Jul 18 '05 #1
3 2019
Nicolas Fleury wrote:
Hi,
How can I know if a system command doesn't exist? All the ways I
have tried behave like if the system command was existing but returning
one. I don't want to sound provocative, but open in Perl returns an
error in a command doesn't exist, so I'm sure we could have an exception
in the same case for popen in Python?


Small correction, as far as I can see, Perl's open returns the same
error if the command returns 1 or doesn't exist. Same problem there...

Jul 18 '05 #2
Nicolas Fleury <ni******@yahoo.com_remove_the_> writes:
Nicolas Fleury wrote:

[...]
How can I know if a system command doesn't exist? All the ways
I have tried behave like if the system command was existing but
returning one. I don't want to sound provocative, but open in Perl [...]

Haven't tried popen(), but I assume C's system() (of which os.system()
is a trivial wrapper, on posix-y OSes) is implemented in terms of
popen() (or both are implemented in terms of similar lower-level
stuff). I get different return codes from system() depending on
whether the program exists or not, as expected:
os.system("nonsense") sh: nonsense: command not found
32512 os.system("ls") [...snip directory listing...]
0 os.system("ls nonsense") ls: nonsense: No such file or directory
256

John
Jul 18 '05 #3
John J. Lee wrote:
Nicolas Fleury <ni******@yahoo.com_remove_the_> writes:
Nicolas Fleury wrote:


[...]
How can I know if a system command doesn't exist? All the ways
I have tried behave like if the system command was existing but
returning one. I don't want to sound provocative, but open in Perl


[...]

Haven't tried popen(), but I assume C's system() (of which os.system()
is a trivial wrapper, on posix-y OSes) is implemented in terms of
popen() (or both are implemented in terms of similar lower-level
stuff). I get different return codes from system() depending on
whether the program exists or not, as expected:


It doesn't behave like that on Windows... the return value is 1 weither
it's the return value of the command executed of if this command doesn't
exist. What would be nice, I think, would be to encapsulate the
difference, and raise an exception if the command doesn't exist. That
might implies additional code for Windows, but in the end the python
code would be more portable.

Regards,

Nicolas

Jul 18 '05 #4

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

Similar topics

2
by: yawnmoth | last post by:
i'm running the following php script, and where i would expect it to create a file, test.txt, it doesn't. it isn't in the directory i am exectuting the script in, nor can i do cat on it (not that...
6
by: Ron Brennan | last post by:
This is from an application and not an Applet. I believe it goes to stdout but when I do a test and write an abitrary string and then do a search of the hard disk for the string, I can't find...
0
by: Nicolas Fleury | last post by:
Hi, How can we know when using popen if the process returned 1 *or* the requested command is simply not found? I'm using latest ActivePython on Windows. Thx Nicolas
2
by: Xah Lee | last post by:
Python Doc Problem Example: os.system Xah Lee, 2005-09 today i'm trying to use Python to call shell commands. e.g. in Perl something like output=qx(ls) in Python i quickly located the...
2
by: Raquel | last post by:
Why can we not give db2 System commands (commands starting with 'db2' like db2ilist, db2look, db2move etc.) through the Command Center? It is so convenient to retrieve and change commands in the...
1
by: T8 | last post by:
I have a asp.net (framework 1.1) site interfacing against SQL 2000. It runs like a charm 99% of the time but once in a while I get the following "unspecified error". Sometimes it would resolve by...
1
by: Juan R. | last post by:
The initial CanonMath program presented here http://canonicalscience.blogspot.com/2006/02/choosing-notationsyntax-for-canonmath.html] was discussed with several specialists, including father of...
13
by: Gary Wessle | last post by:
hi how can I use $wc -l file_name which puts out the number of lines. #include <cstdlib> using std::system; system (wc -l file_name) I get...
3
by: mike | last post by:
Hi Guys, Following piece of code can capture IOError when the file doesn't exist, also, other unknown exceptions can be captured when I press Ctrl-C while the program is sleeping(time.sleep)....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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,...
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...

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.