0

I have a batch file and contains two perl codings and for Example:

MyBatchfile:

rem This perl coding input is Filename output as an number.  
perl -w E:\Testing\PerlFile_1.pl %1

Need to save the number and produce the same as an input for the second script.

rem This perl coding input is as number from the previous perl script.  
perl -w E:\Testing\PerlFile_2.pl %1

How do I pass the output (Number) from first script into the second script as an input.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
ssr1012
  • 2,573
  • 1
  • 18
  • 30
  • 2
    https://stackoverflow.com/questions/2323292/windows-batch-assign-output-of-a-program-to-a-variable – xxfelixxx Jul 24 '17 at 06:43
  • 5
    Possible duplicate of [Windows batch assign output of a program to a variable](https://stackoverflow.com/questions/2323292/windows-batch-assign-output-of-a-program-to-a-variable) – geisterfurz007 Jul 24 '17 at 07:21
  • I couldn't understand from the above links since I am newbie in batchfile programing. – ssr1012 Jul 24 '17 at 07:40
  • In what way does the perl script return the number? As errorlevel or written in the console? @ssr1012 – geisterfurz007 Jul 24 '17 at 07:47
  • Yes. The first script will return the number and the second script will get the input as an number from the first script. – ssr1012 Jul 24 '17 at 07:54
  • Store the output of the first script in a variable. Then use that variable as part of the input for the second script. – xxfelixxx Jul 24 '17 at 07:58
  • @ssr1012 **HOW** will it return the number? It makes a difference in the solution. Errorcode (something like `exit(number)`) or will it be printed in the console? – geisterfurz007 Jul 24 '17 at 08:59
  • It will printed in the console and need to transfer the value into the second script. – ssr1012 Jul 24 '17 at 09:23

1 Answers1

1

You can get the output of a command using:

for /f "delims=" %%p in ('myCommand goes here') do (
set myVar=%%p
)

REM here myVar has the output of the command issued in the above loop
REM assuming that %1 represents the paramter here, I replaced it with the variable above
perl -w E:\Testing\PerlFile_2.pl %myVar%

for /f is used in batch to parse either the contents of the file (in (filename.extension)), a string (in ("myString")) or command outputs (in ('myCommand')). Note the differences in quotation used to determine which one is used.
%%p is the loops parameter and will hold the value of the current iteration. This will be the value in your case. However as this will only exists during the loop we save it to a variable for later use.

geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
  • `for /f "delims=" %%p in ("perl -w myscript1.pl %1") do ( set myVar=%%p ) perl -w myscript2.pl %myVar% echo` – ssr1012 Jul 24 '17 at 10:41
  • I am trying based on the your opinion.. Please check this correct or not...? – ssr1012 Jul 24 '17 at 10:42
  • 1
    Not it is not. Note what I mentioned in the explanation of `for /f`: "[...] or command outputs (`in ('myCommand')`)" You have to use single quotes. And I don't know what the echo at the end is for ^^ – geisterfurz007 Jul 24 '17 at 11:00