Is there a way for the Windows shell script to execute everything in relation to its location and not the location from which it was called?

I am aware of% ~ dp0, which represents a fully expanded directory containing a batch script, but I am looking for:

  • a method to call the script package from Perl in a way that allows me to use the script package unchanged and have all directories in it relative to the script location package
  • one statement I can put into the batch script, which is a flag to use the location of the batch script as a starting point for all directories

I am currently calling a batch script using this method in Perl:

`"../run.bat" -f $ARGV[$#ARGV]`;

      

and then grabbing the output and processing it.

+2


source to share


3 answers


I'm not entirely sure I understand your question. But why don't you just change the current directory in your perl script to the batch script directory and then call the batch script?



+5


source


Use pushd and popd . Add the line

@pushd %~dp0

      

before the batch starts. This will change the working directory to the base directory of the batch file. For completeness (and in case the batch file will be used by other batch files), you should add



@popd

      

at the end.

+3


source


Here's a bat script that starts the catalyst server perl script contained in a location relative to the .bat script: MyPhp / script /

set bindir=%~dp0
set perlpath=%bindir%perl\bin
set buildpath=%bindir%\bin
set PATH=%PATH%;%perlpath%;%buildpath%
"%perlpath%\wperl.exe" "%bindir%MyPhp\script\myphp_server.pl" -p 35900

      

Here's a VBS script to run this same script without highlighting the cmd window:

Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) &  fso.GetParentFolderName(wscript.ScriptFullName) & "\perl shell.bat"& Chr(34), 0
Set WshShell = Nothing

      

Really awful stuff, but it works

0


source







All Articles