I need to run the following command from inside a Perl script in Windows. The code can't be simpler than this:
#! C:\Perl\bin\perl
perl -e "print qq(Hello)";
I save this file as test.pl. I open a command prompt in Windows and run the following from the c:\Per\bin directory. When I run it as perl test.pl, I get the following result:
C:\Perl\bin>perl test.pl
syntax error at test.pl line 3, near ""perl -e "print"
Execution of test.pl aborted due to compilation errors.
How can I fix this? If I just run perl -e from the command prompt (i.e. without being inside the file) it works great.
The test.pl file should contain:
print qq(Hello);
Why would you want to run perl code with perl -e …? Just put the actual code in your program.
If, on the other hand, you want to run an external command from within your program, then the answer depends on what you want to do with the input/output and/or the exit code of your program. Have a look at system, qx and open.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With