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.

8
  • 2
    stackoverflow.com/questions/2323292/… Commented Jul 24, 2017 at 6:43
  • 5
    Possible duplicate of Windows batch assign output of a program to a variable Commented Jul 24, 2017 at 7:21
  • I couldn't understand from the above links since I am newbie in batchfile programing. Commented Jul 24, 2017 at 7:40
  • In what way does the perl script return the number? As errorlevel or written in the console? @ssr1012 Commented Jul 24, 2017 at 7:47
  • Yes. The first script will return the number and the second script will get the input as an number from the first script. Commented Jul 24, 2017 at 7:54

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

for /f "delims=" %%p in ("perl -w myscript1.pl %1") do ( set myVar=%%p ) perl -w myscript2.pl %myVar% echo
I am trying based on the your opinion.. Please check this correct or not...?
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 ^^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.