473,406 Members | 2,208 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,406 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 6069
> 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()) } 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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,...

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.