473,397 Members | 2,028 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,397 software developers and data experts.

execute command in CURRENT shell

Hi,
simple question, how to execute command in current shell, not in
subshell?

Example. I have environment variable A=aaa and need to invoke shell
(sh) script which will do something with A. If I do os.system() then
sub-shell will setup A
and execute my script there leaving A in parent shell untouched.

Thanks,
Valentine.
Jul 18 '05 #1
1 10980
Valentine Kouznetsov wrote in news:ec6d1a16.0308080828.367f6b54
@posting.google.com:
Hi,
simple question, how to execute command in current shell, not in
subshell?

Example. I have environment variable A=aaa and need to invoke shell
(sh) script which will do something with A. If I do os.system() then
sub-shell will setup A
and execute my script there leaving A in parent shell untouched.


A hack for you:

Create a new sh script. say new.sh:

#!/bin/sh
source $*
echo Result=$A
# ----------------
#!/bin/python
import os

command="original.sh arg1, arg2" # you get the idea

#Sorry don't know how you need to invoke sh
w = os.popen( "sh ./new.sh " + command )

while ( True ):
s = w.readline()
if not s:
break
if s.startswith( "Result=" ):
os.environ[ "A" ] = s[ s.find( "=" ) + 1 : ] )
break
# Or maybe read all lines - so you get the last "Result="!

w.close()

HTH

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 18 '05 #2

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

Similar topics

4
by: Kartik | last post by:
Hi, I have an ASP.NET application using VB.NET.I am sending a DOS command to a machine on the network to print a file. This is achieved using xp_cmdshell Dim str As String = "xp_cmdshell...
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...
8
by: zhiwei wang | last post by:
I remember that there is a function that could invoke shell command such as "rm" "cp", directly in .c file. But I could not recall its name, and I googled with nothing meaningful. I vaguely...
3
by: BROQ | last post by:
Hi, I am using a windows service to extract every hour a log from our mailserver in order to parse the logfile. To do this I used the folowing code: Shell("""C:\pscp"" -pw *******...
4
by: alberto | last post by:
How can I execute a command of the operating system like "cls" from a C# code? Thank you
7
by: spec | last post by:
Hi all, I know nothing about Python. What I need to do is to get a Python script to execute a local shell script. I do not need any output. What would be th eeasiest way to accomplish this? ...
9
by: sohan | last post by:
Hi, I want to know how to connect and execute a db2 query from inside a UNIX shell script. Details: We have a unix shell script. We need to execute multiple db2 sql queries from this shell...
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...
4
by: coetzer | last post by:
Help please I am trying to execute a shell.exe which requires a command for usage in VB.Net so the shell is in folder "tmp" c:\tmp> shell.exe and then the command follows: c:\tmp> shell.exe...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.