简体   繁体   中英

Invoking command with custom environment variables

How do i do the equivalent of this bash style command invocation in powershell 1.0

output = `VAR1=value /path/someCommand`

In essence i need to manufacture a private & temporary $env:VAR1 for the purpose of invoking someCommand.

You can set a process environment variable in PowerShell like so:

$env:VAR1 = 'value'

Then invoke the command:

/path/someCommand

Then remove the process env var:

remove-item Env:\Var1

Assuming you want to store the output of that command in var1:

$var1 = $_ | /path/someCommand

Assuming you want an alias so output will run that code whenever called:

Set-Alias output "$var = /path/someCommand"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM