better use of os.system()

B

Bob Roberts

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?
 
D

Daniel Dittmar

Bob said:
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
 
F

Fooman

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
 
C

cmkl

Fooman said:
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
 
B

Bob Roberts

Fooman said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top