Can the batch version of the script know if it is being called from PowerShell?

Is there a way the batch script can know if it was called from PowerShell (no additional parameters)?

You need something like ..

if (%THIS_BATCH_CALLED_FROM_POWERSHELL%)
    ... warn the user or drop back to powershell to execute the proper instructions...

      

The question is related to this question - virtualenv-in-powershell .

+2


source to share


3 answers


You can use a tool like "tlist.exe / t" or this one to display the PIDs of the current process and all parent processes. You can check each of these PIDs to see if the PowerShell.exe files match.



+3


source


You can add a default warning to your script and pass a flag to it that tells it not to show the warning. When you call it from a power shell, pass this flag.



0


source


In my Powershell environment (PS 2.0 CTP) I seem to have a PSMODULEPATH environment variable that is not set by the normal command line environment but still exists when Powershell has a CMD.exe child shell.

I think you might be able to "reliably enough" check for PSMODULEPATH in your script package.

0


source







All Articles