Krin123
Krin123

Reputation: 343

how to tell if a script is running independently or called as subprocess in python

I have two scripts, A.py and B.py let's call them. A is an independent script that can run on its own, but can also be run by calling it from B. B on the other hand needs A to complete. I need to include something in my A script so that a couple configurations can be altered depending on where it's being called from.

I'm calling A from B like this: subprocess.call("A")

What can I do to let A know that it was called from B?

Upvotes: 1

Views: 58

Answers (1)

Daniel
Daniel

Reputation: 42758

Use command line arguments:

subprocess.call(["A", "--called-from-B"])

Upvotes: 2

Related Questions