Use environment variable in path and argument in the same command [duplicate] - powershell

This question already has answers here:
Powershell chmod on /tmp/hive for winutils and hadoop/spark
(1 answer)
Safest way to run BAT file from Powershell script
(8 answers)
Closed 3 years ago.
I have created an environment variable IGNITE_HOME and then want to use this variable to execute a program in PowerShell as well as passing arguments
If I run the following two commands separately, it works fine:
cd $env:IGNITE_HOME/bin
./ignite.bat $env:IGNITE_HOME/examples/config/example-cache.xml
but If I try to run it in one line, it does not work:
$env:IGNITE_HOME/bin/ignite.bat $env:IGNITE_HOME/examples/config/example-cache.xml
I get an error message:
You must provide a value expression following the '/' operator.
At line:1 char:18
I tried to add double quotes on the arguments, but that did not help either

Related

How to turn "abc.exe" to abc in Command Line [duplicate]

This question already has answers here:
Adding a directory to the PATH environment variable in Windows
(21 answers)
Closed 6 months ago.
I want to run this command line: "C:\Program Files\LOVE\love.exe" "C:\games\mygame"
But it's too long, can i turn this into: love "C:\games\mygame"?
You have to add C:\Program Files\LOVE\ to the PATH environment variable. This way, the command can be found from the commandline without explicitly specifying the path.
See https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them on what environment variables are and how to set them in Windows.

How can I define/use a powershell command result in Jenkins as a Jenkins Variable? [duplicate]

This question already has answers here:
Jenkins scripted pipeline: Unable to print variables inside shell and set variable values in shell
(2 answers)
Closed 2 years ago.
I am trying to define the valor obtained from powershell command as a valor for one Jenkins variable that I use at the same stage(outside powershell command). I can not resolve that! Any idea to help me!
final NAMEUPDATE
steps {
script {
powershell '''
$nameupdate = get-content D:\\updates\\nameupdates.txt
'''
NAMEUPDATE = $nameupdate
Try this:
script {
NAMEUPDATE = powershell 'get-content D:\\updates\\nameupdates.txt', returnStdout: true
}
The documentation for the powershell step says the following regarding the returnStdout argument:
If [true], standard output from the task is returned as the step value as a String, rather than being printed to the build log. (Standard error, if any, will still be printed to the log.) You will often want to call .trim() on the result to strip off a trailing newline.

What's the equivalent of 'set -e' (exit on any errors) in Powershell? [duplicate]

This question already has answers here:
How to stop a PowerShell script on the first error?
(11 answers)
Closed 3 years ago.
I've been using Unix for about 20 years, but only started using Powershell recently. I have a ps1 script that does a number of tasks.
I know I could check each of them, and throw if they error, but it would be good for the entire script just to exit on any errors - like set -e does in bash.
How can I make a Powershell script exit immediately upon any error?
Using pwsh 6.2.1.
Having just found the answer to my own question:
ErrorActionPreference does this.
$ErrorActionPreference='Stop'
at the top of the ps1 file.

Set shell variable with help perl script [duplicate]

This question already has answers here:
How do I set an environment variable in Perl?
(5 answers)
Closed 6 years ago.
I was trying to set shell variable name with help of perl script.
But it was not running fine.
system("variable_name=\"variable_value\"");
`variable_name=\"variable_value\"`;
Any one tell me why it was not working.
Actually my question was little bit different.
I want to know how to set environment "setenv" with help of perl script.
I have tried
$ENV{"VARIABLE_NAME"} = "home\/path_1\/path_2\/path_3";
Then I fire command echo $VARIABLE_NAME then it is not giving me path that I set from perl script.
Thanks
You have no need to run a new shell to set an environment variable; indeed, doing so is counterproductive, since the value doesn't outlive the shell in which it's assigned (except through any surviving children of that shell which may have inherited the value).
You can simply set an environment variable directly in your perl:
$ENV{"variable_name"} = "variable_value"
Any subsequent shell you start from your perl script will see this.
It was working. The problem is that the next system command runs a new shell which doesn't know about variables set in the first shell.
system 'x=value; echo $x'; # Outputs "value".
system 'echo $x'; # Empty line - the shell with $x doesn't exist anymore.

Startup Parameters within the Script? [duplicate]

This question already has answers here:
Is there a way to programmatically set the ApartmentState to STA?
(2 answers)
Closed 7 years ago.
I have a script that needs to run in single-threaded mode, and I currently start it up with the -sta parameter with a batch. Is it possible to run the script in -sta mode only executing the Script? I thought about moving the whole script into one function and execute this function in single-threaded mode.
Is that possible? I don't want to give out a batch file and my ps1.
I think if you were to get PowerGUI and put the script into this, you would be able to package the PS1 file into an exe file which can just be executed like a normal program.
Once PowerGUI is installed you can do this from Tools, Complile Script.