• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

batch file to run two executables with command line arguments

i want to write a DOS batch file that will parse out multiple parameters and use they to run two exes in sequence.

so it will be something like this:

arg1 = %1
arg = %2
...

exe1 arg1 arg2
exe1 arg5 arg6 ...

the problem is that my batch file only allows me to have up to 9 arguements, but anything beyond that it seems to not work.  also i want to be able to concatenate two arguments into 1.  ideally, the order of the arguments should not matter to account for human errors.  thanks.

@echo off

:initial
if "%1"=="-filepath" goto lfilepath
if "%1"=="-source" goto lsource
if "%1"=="-destination" goto ldestination
if "%1"=="-username" goto lusername
if "%1"=="-privatekey" goto lprivatekey
if "%1"=="-publickey" goto lpublickey
if "%1"=="-server" goto lserver


if "%1"=="" goto print
goto error

set str1 = "pgp"

:lfilepath
shift
set filepath=%1
goto lreturn

:lsource 
shift
set source=%1
goto lreturn

:ldestination
shift
set destination=%1
goto lreturn

:lusername 
shift
set username=%1
goto lreturn

:lprivatekey 
shift
set privatekey=%1
goto lreturn

:lpublickey 
shift
set publickey=%1
goto lreturn

:lserver 
shift
set server=%1
goto lreturn


::set "str3 = %filepath%%str1%"


:lreturn
shift
call test.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 
goto run

:error
echo %0 usage error
goto run

:print
echo filepath = %filepath%
echo source = %source%
echo destination = %destination%
echo username = %username%
echo privatekey = %privatekey%
echo publickey = %publickey%
echo server = %server%
echo str = %str1%
::echo str3 = %str3%

:run
::FileEncrypt filepath source destination
C:\JobQueueShare\Executables\curl_7_20_0\curl -u %username%: --key %privatekey% --pubkey %publickey% -T "C:\temp\test5.txt.pgp" %server% --insecure

Open in new window

0
mmingfeilam
Asked:
mmingfeilam
  • 2
1 Solution
 
Bill PrewCommented:
Try this and see if it makes sense.

@echo off
setlocal EnableDelayedExpansion

:DoParms
  if "%~1" EQU "" goto :GotParms
  set Parm=%~1
  set !Parm:~1!=%~2
  shift
  shift
  goto :DoParms

:GotParms
echo filepath = %filepath%
echo source = %source%
echo destination = %destination%
echo username = %username%
echo privatekey = %privatekey%
echo publickey = %publickey%
echo server = %server%

set str1 = "pgp"
set "str3 = %filepath%%str1%"
echo str = %str1%
echo str3 = %str3%

::FileEncrypt filepath source destination
C:\JobQueueShare\Executables\curl_7_20_0\curl -u %username%: --key %privatekey% --pubkey %publickey% -T "C:\temp\test5.txt.pgp" %server% --insecure

Open in new window

~bp
0
 
mmingfeilamAuthor Commented:
everything seems to work except that str1 and str3 are empty.
@echo off
setlocal EnableDelayedExpansion

:DoParms
  if "%~1" EQU "" goto :GotParms
  set Parm=%~1
  set !Parm:~1!=%~2
  shift
  shift
  goto :DoParms

:GotParms
echo filepath = %filepath%
echo source = %source%
echo destination = %destination%
echo username = %username%
echo privatekey = %privatekey%
echo publickey = %publickey%
echo server = %server%

set str1 = "pgp"
set "str3 = %filepath%%str1%"
echo str = %str1%
echo str3 = %str3%

::FileEncrypt filepath source destination
C:\JobQueueShare\Executables\curl_7_20_0\curl -u %username%: --key "%privatekey%" --pubkey "%publickey%" -T "C:\JobQueueShare\File Drop\Lam\Fidelity\Encrypted\test5.txt.pgp" "%server%" --insecure

Open in new window

0
 
Bill PrewCommented:
Sorry, I was more focused on the parm handling I missed the syntax errors on those.  For SET commands, there can't be any spaces around the equal sign, so change those to this.  Also, it's usually best not to include any quotes in the set values, and just quote when you reference the variable later if needed.

set str1=pgp
set str3=%filepath%%str1%
echo str = %str1%
echo str3 = %str3%

~bp
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now