Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8439827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:06:42+00:00 2026-06-10T08:06:42+00:00

When my PHP script runs a subprocess (with any of the relevant functions such

  • 0

When my PHP script runs a subprocess (with any of the relevant functions such as exec(), system(), passthru(), popen(), proc_open(), and maybe others I’ve forgotten) I can control the values of environment variables the process starts with (either by changing the script’s environment itself, or, at least in the case of proc_open(), by passing the desired environment as an argument). But is there a way for my script to get the state of the environment the process finishes with (that is the process potentially changes the environment, and I wish my script to be able to track those changes). Using getenv() is useless as the script`s environment is not changed by the subprocess. Any ideas regarding whether this can be done, and how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:06:44+00:00Added an answer on June 10, 2026 at 8:06 am

    So, I don’t like it, but this is what I’ve come up with: I’ve written a script that outputs the whole environment as a single line, and I’m calling it right after my invoked process, as part of the same command. After that I can analyse the output, extracting the environment from the last line, and discarding it in order to process the output from my original process.

    There are many options to implement this. What I’ve done is along the lines of:

    1) Creating a Python script, naming it, for example printenv, which looks like this:

    #!/usr/bin/python2.7
    import os
    print os.environ
    

    2) When invoking my process, instead of <some command> I invoke <some command> && printenv.

    Of course, the script does not have to be in Python, and it does not have to output the environment in Python’s print format. (But this format is rather convenient, and can be passed to a JavaScript assignment, for example.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script that runs this command: system(pdftohtml -i -noframes /home/myacc/pdfs/test.pdf); When
Possible Duplicate: php in background exec() function After a certain script runs on website
I have a php script that is run once a minute. The script runs
Hi guys I have a weird question, I have a cli php script runs
I have a php script that runs a mysql query, then loops the result,
I'm working on a PHP script that runs a Python script on the server.
I have a command-line PHP script that runs a wget request using each member
I was wondering how to make a php daemon script that runs one time
I have a form in html which runs a php script whitch inserts text
The code below gets the username/password and runs it thru the backend.php script. <?php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.