0

I want to call another program and return while it is running I can use this

start /MIN "Updating Local Utilities" UPutils ^&^& exit

and that works great.

But I want to pass arguments to the started instance.

These methods don't work:

rem pass along literal parameters
start /MIN "Updating Local Utilities" UPutils C:\source  c:\Target  ^&^& exit

rem pass along dynamic parameters
start /MIN "Updating Local Utilities" "UPutils %Source% %Target%"  ^&^& exit

but that is the idea of what I want.

My receiving program (UpUtils.bat) would simply use them as %1 and %2 arguments

Echo %1
Echo %2

Thanks

1
  • Assuming of course UpUtils.bat is in a dir in %PATH%, your first method (with constant values) should work and does for me, and the second (with %var%) also if you remove the extra quotes around the command (i.e. batchfile) and args. And BTW the ^&^& exit is unneeded and useless. Commented Oct 27, 2020 at 9:32

2 Answers 2

0

Ok. Sometimes ya just want to get it done!

Standing on the shoulders of giants (HERE)...

Most of this code is the direct result of questions answered right here in this forum! Thank you all for the knowledge you have passed on so willingly.

There are three files involved. The first batch file STARTs the other batch file. The third file is the storage place for the passed arguments. I still hope there is a way to more easily pass arguments with the START command, but sometimes...

PassArgs.bat --> RecArgs.bat Repository.ARGS

Here is the Passing Program:

@echo off
echo  ---- PassArgs.bat ----
 Echo Arg1 >  Repository.ARG
 
 Echo Arg2 >> Repository.ARG

 start "Passing Arguments" RecArgs ^&^& exit

 ((((echo Just waiting for...) & echo RecArgs ) & echo Oh look. It's done!.) & echo.)|MSG /time:5 *

 echo That's All Folks!
 echo.

And here is the receiving batch program:

@echo off
echo ---- RecArgs.bat ----
  cd /d "%~dp0" && setlocal EnableDelayedExpansion

  for /f ^tokens^=*delims^= %%i in ('type Repository.ARGS')do set /a "_c+=1+0" && <con: set "Arg!_c!=%%~i"

  for /l %%l in (1 1 !_c!)do echo\Arg%%l=!Arg%%l!

  %__AppDir__%timeout.exe -1 & endlocal & goto=:EOF


  echo Arg1=%Arg1%
  echo Arg2=%Arg2%

  Echo  I got them!
  echo.

pause

The end result is arguments Arg1 and Arg2 passed to the STARTed program.

Arg1="Arg1"
Arg2="Arg2"
-1

You can't pass arguments to a started instance of a program, now running a different start statement will create a new instance of the program with new arguments. AFAIK this is nearly impossible and Developer nightmare in a language like Batch to implement.

5
  • Wow! That seems like extreme oversight on Microsoft's part. They allow me to pass arguments with a call to another batch, but not with Start. Well I guess I could create a text file with the intended parameters, and a routine in the "Started" program to read in that text file. But why MS? – In case there is any misunderstanding: I'm not trying to do this recursively. They are different named programs.
    – WithaKay
    Commented Sep 21, 2020 at 12:28
  • @WithaKay I was also thinking of the same idea. But there goes the nightmare, hard blocks of code to implement!! Like your batch file runs, and then you need to launch a seperate a controller like batch file to read the file and pass it again, which puts us to an endless loop, where the MSFT start and argument passing again getting involved. But if the program is simple, then the idea could be replaced with like you run a few simple commands, put them between an endless forever looping goto based loop, and at the end of the sub routine, use code to check for modified entries. [Cont'd]
    – Wasif
    Commented Sep 21, 2020 at 13:12
  • [Cont'd] @WithaKey but seems that your batch file is quite complex, and actually this idea is not so prompt because, whenever you write to a file, first the text goes to the text file, and once the UPUtils.bat loops itself, it has to perform all the statements and at last when it reaches EOF, then it parses the text file and gets the refreshed/updated arguments and continues. So, because of not being prompt it will not be reliable. So the best idea is to launch multiple instances of your batch file (UPUtils.bat), with different arguments, you can see that you're calling the same [Cont'd]
    – Wasif
    Commented Sep 21, 2020 at 13:15
  • [Cont'd] batch file and it contains the same code (Unless you modify in the middle) and batch files won't make your CPU or memory slow much, then you can easily run multiple instances. Who do the same task but on different things (by things I mean the passwd arguments) (Sorry for the too much complicated writing, plz notify me if you are having trouble to digest) [No more continuation, End]
    – Wasif
    Commented Sep 21, 2020 at 13:17
  • You absolutely can pass arguments when a command (including a batchfile) is STARTed, although you can't change or add them afterwards. Commented Oct 27, 2020 at 9:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .