469,330 Members | 1,329 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

better use of os.system()

How can I make it so that I can pass anything into os.system() any
command that I would type into the command line (bash on cygwin)? For
example, "lower" is a small script of mine that I use frequently, and
I would like to be able to call if from python. os.system("lower")
results in:
lower: not found

I want it to run "lower" just like it would if I typed "lower" at the
bash prompt. How can I do that?
Jul 18 '05 #1
4 45620
Bob Roberts wrote:
How can I make it so that I can pass anything into os.system() any
command that I would type into the command line (bash on cygwin)? For
example, "lower" is a small script of mine that I use frequently, and
I would like to be able to call if from python. os.system("lower")
results in:
lower: not found

I want it to run "lower" just like it would if I typed "lower" at the
bash prompt. How can I do that?


If you're using the standard windows Python distribution, try setting
%CMDSPEC% to the path of your bash.exe.

If you're using the cygwin python, then I don't know if CMDSPEC or SHELL
is the right one.

Daniel

Jul 18 '05 #2
lower: not found

I want it to run "lower" just like it would if I typed "lower" at the
bash prompt. How can I do that?


The problem is that the 'lower' script is not in the path that
the python interpreter knows about. You can do:

os.system("/my/nonstandard/pathto/lower")

or, if you are using Linux, or similar, you can try
making sure that your $PATH variable is getting set to
include the path to your script in the environment that
the python interpreter gets launched in.

So, what platform are you running under, and what is the
path to your 'lower' script, and what are the contents
of your $PATH variable?

Tobiah

Jul 18 '05 #3
Fooman <fe*@fee.com> wrote in message news:<18******************************@news.terane ws.com>...
lower: not found

I want it to run "lower" just like it would if I typed "lower" at the
bash prompt. How can I do that?


The problem is that the 'lower' script is not in the path that
the python interpreter knows about. You can do:

os.system("/my/nonstandard/pathto/lower")

or, if you are using Linux, or similar, you can try
making sure that your $PATH variable is getting set to
include the path to your script in the environment that
the python interpreter gets launched in.

So, what platform are you running under, and what is the
path to your 'lower' script, and what are the contents
of your $PATH variable?

Tobiah


You can use the standard windows Python distribution with
a little trick. First of all make sure you can start 'lower'
from a dos console.
To do that, you need a little helper cygwin shell script:

- start cygwin

- cd /bin

- create a cmd2bash script with the following content:

#! /bin/bash
$*

- chmod +x cmd2bash (make it executable)

Then start a console and try out following command:

C:\>c:\cygwin\bin\bash c:\cygwin\bin\cmd2bash "ls -la"

Do you see the content of drive C:\ in posix style?
You may need to adjust the path to cygwin.

If you have name with spaces (barf) you may need single quotes:
C:\Programme>c:\cygwin\bin\bash c:\cygwin\bin\cmd2bash "ls 'Outlook Express'"

Then try to start your lower script with:
os.system('''c:\cygwin\bin\bash c:\cygwin\bin\cmd2bash "lower"''')

btw: this trick works for msys too

Regards

Carl
Jul 18 '05 #4
Fooman <fe*@fee.com> wrote in message news:<18******************************@news.terane ws.com>...
lower: not found

I want it to run "lower" just like it would if I typed "lower" at the
bash prompt. How can I do that?


The problem is that the 'lower' script is not in the path that
the python interpreter knows about. You can do:

os.system("/my/nonstandard/pathto/lower")

or, if you are using Linux, or similar, you can try
making sure that your $PATH variable is getting set to
include the path to your script in the environment that
the python interpreter gets launched in.

So, what platform are you running under, and what is the
path to your 'lower' script, and what are the contents
of your $PATH variable?

I am running under cygwin (it acts like linux in many respects), using
the cygwin-built version of python. The path to "lower" is
~/bin/lower, and ~/bin is in my $PATH.
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

220 posts views Thread by Brandon J. Van Every | last post: by
3 posts views Thread by Muhd | last post: by
15 posts views Thread by ham-z | last post: by
22 posts views Thread by David Sterling | last post: by
16 posts views Thread by Robert Zurer | last post: by
1 post views Thread by Chad A. Beckner | last post: by
3 posts views Thread by Paul | last post: by
43 posts views Thread by Rob R. Ainscough | last post: by
1 post views Thread by unwantedspam | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.