Closed lastcoolnameleft closed 6 years ago
I always avoided commands that required human interaction. How can we automate that in a demo / test scenario? insteead I've used template files, environment variables and text processing to create necessary files in an automated way. This has the added advantage of forcing the author to provide template files with tokens for replacement.
But, to your question about subprocess. Originally I used Subprocess. One of the reasons I moved away was because, exactly as you say, it does not preserve the environment.
Ok, darn. I was hoping you might have some magical insight that I missed.
Closing this point since we're on the right path.
This issue is to document an experiment I tried recently and possibly get suggestions for an alternative.
Pexpect doesn't let you run commands which take over the terminal. (For example, running vi) This is frustrating as that limits runnable commands that promote interactivity.
I experimented with Python's Subprocess and was hopeful, but ultimately it did not meet the needs.
Opens up VI session! Great! However, I could not find a way to keep the session open. If I set an environment variable, then the next time I ran subprocess.call(), the env var was gone.
I'm hoping to be proven wrong, and would like to explore further, but this is the limitation I hit. I tried using lower-level calls, such as communicate(), but could not make progress.
https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate
Essentially subprocess lets you run a single command; however, I could not find a way to keep the session alive, as it appears to close upon hitting an EOF. And once you called communicate(), the session was closed.