1

I know that one should not mix languages but I don't find another way.

I have a Batch Script that starts a Perl Script. This Perl Script writes a value in a variable. I want that that the Perl Variable is returned to a Variable within the Batch Script.

Batch-Script:

:: Log-File
set logfile=.\yesterday_%TIMESTAMP%.log

:: start main program
call :main >>%logfile% 2>&1
exit /b

:: main program
:main

call "C:\myperl\perl\bin\perl.exe" ".\yester.pl"

Perl-Script:

use DateTime qw( );
use Date::Parse;
use Date::Language;

my $lang = Date::Language->new('German');

my $yday_date =
   DateTime
      ->now( time_zone => 'local' )
      ->set_time_zone('floating')
      ->truncate( to => 'day' )
      ->subtract( days => 1 )
      ->epoch;

print $lang->time2str('%b%d', $yday_date) . "\n";

Is this even possible and if yes, how?

Any answer is appreciated.

ste92
  • 434
  • 9
  • 23
  • 1
    Does https://stackoverflow.com/questions/6359820/how-to-set-commands-output-as-a-variable-in-a-batch-file answer your question ? – merours Dec 09 '20 at 14:29
  • I found another way see my answer below. Thanks anyway – ste92 Dec 09 '20 at 14:53

1 Answers1

2

I found a way. This line in the batch script works for me:

for /f "tokens=*" %%a in ('perl yester.pl') do set yester=%%a
ste92
  • 434
  • 9
  • 23