how to run the perl script in the directory which i specify while running the script in the command line [duplicate] - perl

This question already has answers here:
How do I cd into a directory using perl?
(3 answers)
Closed 9 years ago.
How to run the perl script in the directory which i specify while running the script in the command line
Example:
./scriptname -rd run
My script should go to directory name run and it should run there?

Do a chdir() in your Perl script.
cf http://perldoc.perl.org/functions/chdir.html

The obvious solution is to chdir to the directory before running the script:
dir=$(readlink -f .)
cd run
"$dir"/scriptname

Related

Use of ls -la on windows OS [duplicate]

This question already has an answer here:
Error trying to list files in directory using the ls -la command
(1 answer)
Closed 16 days ago.
software devs it is requested to help me. I want to use the ls -la command on the vs code terminal. It is not working
enter image description here
I tried setting the execution policy to unrestricted. It got unrestricted but it still didn't work. Look i have used ls -la command on a kali linux vm in the past. Currently i am trying to usxe it on a windows default os running vs code and it isn't working. Please help me. Regards
ls is a unix command. The equivalent for that in windows is dir.
If you still want to use 'ls', better of setting it as an alias for dir.
ls -la is a linux command that displays all the files including hidden files in long format. The equivalent of it on Windows is dir /a

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.

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.

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

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

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.