How to return a perl variable to DOS

There must be a better way of doing it than this….. I couldn’t find a way of ‘return’-ing a variable from perl to dos in the way that you can with an Oracle function or a unix shell script.

This only works if you only have one line to stdout, so its vulnerable to getting unexpected lines output in the perl. You could improve it by prefixing what you want returned with a string then using findstr on the output, but it’s still fairly manky

Anyway this it:

x.pl is:
print “nHello”;

If you run the perl using the for syntax, you can get the output into a variable
C:>for /f “tokens=1” %I in (‘d:perlbinperl x.pl’) do set myvar=%I

C:>echo %myvar%
Hello

Neither big nor clever….

Advertisements