473,385 Members | 2,014 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.

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 45841
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
3
by: Muhd | last post by:
<usualDisclaimer>Please forgive me if this is in the wrong group, and if so, what is the right group.</usualDisclaimer> Let me start off by first saying im a newb. Ok, with that out of the way I...
15
by: ham-z | last post by:
I have written the following Win app in VB.NET 2003 . The class is simply picture boxes that behave in a random order after they have been instantiated and added to a form. When I create 15 or more...
133
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
22
by: David Sterling | last post by:
After much futzing about with the XML/XSD for the Search.Response, I had to resort to this... PLEASE Tell me there is a better way! private void ExecuteAQuery(string strLookingForWhat) {...
16
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
1
by: Chad A. Beckner | last post by:
Hey all, I am developing a workshop registration system, and am new to ASP .NET. On my first page, I want to list the "categories" available along with the number of "workshops" related to that...
3
by: Paul | last post by:
With respect to performance, is either of these better? Dim myTextBox As New TextBox or Dim myTextBox As TextBox myTextBox = New TextBox or
43
by: Rob R. Ainscough | last post by:
I realize I'm learning web development and there is a STEEP learning curve, but so far I've had to learn: HTML XML JavaScript ASP.NET using VB.NET ..NET Framework ADO.NET SSL
1
by: unwantedspam | last post by:
I am new to asp.net. Is there a better way to do the following code? Dim Cell1 As New System.Web.UI.WebControls.TableCell Dim Cell2 As New System.Web.UI.WebControls.TableCell Dim Cell3 As New...
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: 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
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.