We help IT Professionals succeed at work.

batch file to run two executables with command line arguments

mmingfeilam
mmingfeilam asked
on
359 Views
Last Modified: 2012-06-21
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

Comment
Watch Question

Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
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

Author

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

Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.