473,507 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: subprocess with shared environment?

On Mon, 2008-11-17 at 15:27 -0800, rowen wrote:
I'd like to replace some shell scripts with Python, but one step of
the script modifies my environment in a way that the subsequent steps
require.

A simple translation to a few lines of subprocess.call(...) fails
because the first call modifies the environment, but the other lines
don't see it.

Is there a straightforward way to do this (without having to resort
to writing some of it as a shell script)?

-- Russell
>From the subprocess docs
subprocess.call = call(*popenargs, **kwargs)
Run command with arguments. Wait for command to complete, then
return the returncode attribute.

The arguments are the same as for the Popen constructor. Example:

retcode = call(["ls", "-l"])
....

class Popen(args, bufsize=0, executable=None,
stdin=None, stdout=None, stderr=None,
preexec_fn=None, close_fds=False, shell=False,
cwd=None, env=None, universal_newlines=False,
startupinfo=None, creationflags=0):

....

If env is not None, it defines the environment variables for the new
process.

....
Environment example:

os.spawnlpe(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg", env)
==>
Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"})
Nov 17 '08 #1
0 1489

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

Similar topics

0
2172
by: Simon | last post by:
Hello. I wanna use my dynamic shared library(built with C language) with php script. (PHP version is 4.0.6) So I making a shared library(*.so) in Solaris environment(2.7) and it is successful....
7
6650
by: Sigfried Manner | last post by:
Hello NG! I have following situation: c-prg | webprg "c-prg" is a small c-programm which reads data from an fastCgi-Server and writes them to stdout. The stdout is piped into webprg....
15
4896
by: Rob Nicholson | last post by:
A consequence of the ASP.NET architecture on IIS has just hit home with a big thud. It's to do with shared variables. Consider a module like this: Public Module Functions Public GlobalName As...
5
1568
by: Simon | last post by:
Hi all, We have an ASP.NET 1.1 application running on IIS6 on Server 2003. Most of the base objects we are using in this application are taken from a windows application also written by us. We...
1
1374
by: calmar | last post by:
Hi all, first of all, I have to say I have hardly no knowledge about that issue. on the program there, I have it like that: ,------------------------------------------------------- | obj...
1
1927
by: Marko Rauhamaa | last post by:
This tiny program hangs: ======================================================================== #!/usr/bin/env python import subprocess a = subprocess.Popen('cat',shell = True,stdin =...
25
2747
by: Jeremy Banks | last post by:
Hi. I wondered if anyone knew the rationale behind the naming of the Popen class in the subprocess module. Popen sounds like the a suitable name for a function that created a subprocess, but the...
7
6204
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...
2
2714
by: rowen | last post by:
I'd like to replace some shell scripts with Python, but one step of the script modifies my environment in a way that the subsequent steps require. A simple translation to a few lines of...
0
7319
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
7376
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...
1
7031
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
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
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,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.