473,385 Members | 1,813 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.

run shell commands


Hello! :)

I'm trying to run shell commands both with os.system() and
subprocess.Popen() class.

But I can't run aliases or function defined in my .bashrc file, like in
the login interactive shell.

Can you help me?
Maybe have I to add some commands to load the .bashrc?

Thanks a lot! :)

Ric.

Jan 10 '08 #1
1 3992
On Jan 10, 2008 9:24 AM, Riccardo Maria Bianchi
<rb******@physik.uni-freiburg.dewrote:
>
Hello! :)

I'm trying to run shell commands both with os.system() and
subprocess.Popen() class.

But I can't run aliases or function defined in my .bashrc file, like in
the login interactive shell.

Can you help me?
Maybe have I to add some commands to load the .bashrc?

Thanks a lot! :)

Ric.

--
http://mail.python.org/mailman/listinfo/python-list
you'd need to run an instance of the shell from python and probably as
a login shell so that it pulls in .bashrc.

so you'd need a command line like: /bin/bash -l -c "shell commands to
run go here"

if you want to feed more commands to bash, then use -s. It will read
commands from standard input, which you would feed it from python,
probably by writing to a Popen pipe.

A lot of people also use the pexpect python library to "drive" other
programs, especially if you need python to act differently depending
upon the output of the called programs.

Either way, this list's archives do have some good examples as to the
uses and limitations of both subprocess and pexpect.

--
Noah Dain
"The beatings will continue, until morale improves" - the Management
Jan 10 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bigbowser | last post by:
Hi all, I'm trying to create a sub shell environment ( i haven't really got a reason, its more of a test, although hopefully it will make life easier ;P ) but whenever i try to call the...
8
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland...
9
by: Amjad | last post by:
I'm trying to create a folder, append text file to another, and delete files using the "Shell" command. But I always get the error "File Not Found". How do I use DOS commands from Visual Basic?...
16
by: John Salerno | last post by:
Hi all. I just installed Ubuntu and I'm learning how to use the bash shell. Aside from the normal commands you can use, I was wondering if it's possible to use Python from the terminal instead of...
7
by: Bin Chen | last post by:
Hi, I want to do following: get a user input regex, then pass this as a parameter to grep, and then get the result from grep. Any code snip to implement the similar function? I am a python...
4
by: Anastasios Hatzis | last post by:
I'm looking for a pattern where different client implementations can use the same commands of some fictive tool ("foo") by accessing some kind of API. Actually I have the need for such pattern for...
1
by: raocheng | last post by:
Please see the following code. Suppose I have many shell commands to be executed. And I don't want to fork a sub shell for each command(eg: status,output = commands.getstatusoutput(cmd)) because...
5
by: inetquestion | last post by:
I am looking for a web interface for shell commands or shell scripts. Does anyone know of any exexisting php scripts which would solve this requirement? PHP form accepts input from a user, then...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.