How do I start a process with environment variables like /usr/bin/env in Windows PowerShell?

Asked 2 years ago, Updated 2 years ago, 76 views

I want to start the process by setting environment variables like the env command on UNIX, but how can I do this with Windows PowerShell?

I understand that the Set-Item command can rewrite the environment variables, but this will rewrite the environment of the shell itself, so I have to undo it later, which is a bit troublesome.

Add

Specifically, I would like to start the unit test with a specific environment variable set.For UNIX shells, you can write:

$ env NODE_ENV = test npm test

(This does not necessarily require env.)

windows powershell

2022-09-30 19:33

1 Answers

PowerShell has a (virtual) drive environment provider that represents environmental variables. $env:name="BLUE"
You can configure environment variables as shown in .(env: represents the drive name, $ represents the variable, and name represents the environment variable name)
The cmdlet can be referenced by $env:name or env:name depending on the cmdlet whether or not $ is required.
Same as the environment variable in the batch, it is disabled at the end of the shell (enabled during the boot process)


2022-09-30 19:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.