472,353 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

os.system()

Hello,

code like

os.system(command)

only works for some values of 'command' on my system (Linux). A certain
shell command (that *does* run on the command line) does not work when
called with os.system(). Does anyone know a simple and stable way to
have *any* string executed by the shell?

Jörg Schuster

Jul 18 '05 #1
9 6009
> only works for some values of 'command' on my system (Linux). A certain
shell command (that *does* run on the command line) does not work when
called with os.system(). Does anyone know a simple and stable way to
have *any* string executed by the shell?


Showing us what commands actually fail would certainly help.
--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
Well, I can give you the string, but that will not help:

transduce abc info_dic comp_dic input_file output_file

For copy right reasons, I am not allowed to give you the program
transduce.

But here are some facts about transduce:

- it is written in C
- it takes an alphabet file (abc) and two automata files (info_dic and
comp_dic) as input and applies the automata files to the input file.

Jul 18 '05 #3
On Monday 07 March 2005 14:10, Diez B. Roggisch wrote:
Showing us what commands actually fail would certainly help.


Actually, this sounds like the subshell isn't getting an alias that the normal
interactive shell has. Maybe because ~/.bashrc isn't read on os.system(), or
something of the like? This depends largely on your default system settings,
and especially on /etc/profile.

You might check whether the command that works in the interactive shell is an
alias by typing

heiko@heiko ~ $ alias
alias ls='ls --color=auto'
heiko@heiko ~ $

This shows all currently set aliases, and at least on Gentoo, the above alias
is set in ~/.bashrc, and thus isn't set when os.system() is called. This
means that the output from running ls in an interactive shell is colorized,
whereas running os.system("ls") from Python is not colorized, although
TERM="xterm" in os.environ, and thusly in the subshell spawned using
os.system, and ls could colorize the output using VT100 escape sequences.

All the above explanations assume that your default shell /bin/sh is the
Bourne Again Shell, but all other "higher shells" such as the (T)C-Shell and
the Korn-Shell support command aliasing too, in some way or another, and will
suffer from the same quirks.

And, btw., it'll help if you read the commented start-up files (at least on
Gentoo and SuSE (IIRC) they are very well commented) and the bash man-page,
they explain pretty clearly which initialization files (~/.bashrc,
~/.bash_profile, /etc/profile, /etc/bash/bashrc, and several others) get
executed when and where, depending on whether a shell is a login shell (your
normal interactive shell), or not (spawned by os.system, for example).

Hope this explanation helps!

--
--- Heiko.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQBCLFZhf0bpgh6uVAMRAuGcAJ4j6O9rC56JRZxyIofNPv qp/NHtjACeJf5q
nySvFSVFx++9iU5XYuzEaT8=
=kWmz
-----END PGP SIGNATURE-----

Jul 18 '05 #4
On Monday 07 March 2005 14:24, Joerg Schuster wrote:
Well, I can give you the string, but that will not help:

transduce abc info_dic comp_dic input_file output_file


Several variables like PATH "normally" get reset even when running a non-login
subshell to the standard values from /etc/profile (on Gentoo /etc/env.d/*),
so I guess that you're just having a problem finding the executable for
transduce if that program isn't installed in a path which is always on $PATH.

At least I know this behaviour from some older versions of SuSE; Gentoo with
bash 3.0-r8 and baselayout 1.11.9-r1 does as I would presume and doesn't
reset it (there goes my example). What you might try:

export PATH="/does/not/exist:$PATH"
echo $PATH
--- Path here ---
python
import os
os.system("echo $PATH")

--- Path here, different? ---

and check whether they are any different. You could also do this for other
important variables, such as LD_LIBRARY_PATH. But, all of this is stabbing in
the dark, maybe you can just send the actual error message along next time.

HTH!

--
--- Heiko.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQBCLFoTf0bpgh6uVAMRAvMLAJ9+L9B/gaZPriJJNWJAnmesW+Pp0wCfcSLH
Pdsjmd5mL2Z0F1Zi6ZRDGec=
=mmAz
-----END PGP SIGNATURE-----

Jul 18 '05 #5
> Several variables like PATH "normally" get reset even when
running a non-login subshell


It seems that this has been the problem. I guess your tip saved me a
lot of time. Thanks a lot.

Joerg

Jul 18 '05 #6
> Several variables like PATH "normally" get reset even when
running a non-login subshell


It seems that this has been the problem. I guess your tip saved me a
lot of time. Thanks a lot.

Joerg

Jul 18 '05 #7
mod subprocess, if you're on 2.4:

http://docs.python.org/whatsnew/node8.html

Jul 18 '05 #8
Joerg Schuster <jo***********************@gmail.com> wrote:
os.system(command)

only works for some values of 'command' on my system (Linux). A certain
shell command (that *does* run on the command line) does not work when
called with os.system(). Does anyone know a simple and stable way to
have *any* string executed by the shell?


The command is exectued through the shell, eg
os.system("sleep 60 > z")


$ ps axf
5121 ? S 0:00 rxvt
5123 pts/77 Ss 0:00 \_ bash
5126 pts/77 S+ 0:00 \_ python
5149 pts/77 S+ 0:00 \_ sh -c sleep 60 > z
5150 pts/77 S+ 0:00 \_ sleep 60

Things to check
1) quoting, python vs shell
2) PATH - check PATH is set the same in shell / python
3) check the whole of the environment

Also if you are using 2.4 check the subprocess module

--
Nick Craig-Wood <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Jul 18 '05 #9

[Nick]
$ ps axf
5121 ? S 0:00 rxvt
5123 pts/77 Ss 0:00 \_ bash
5126 pts/77 S+ 0:00 \_ python
5149 pts/77 S+ 0:00 \_ sh -c sleep 60 > z
5150 pts/77 S+ 0:00 \_ sleep 60


Wow, good feature of ps - thanks for the education!

I learn something valuable from comp.lang.python every week, and most of
it has nothing to do with Python. 8-)

--
Richie Hindle
ri****@entrian.com

Jul 18 '05 #10

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()) } ...
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...
0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI"...
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...
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...
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...
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...
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...
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...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.