I developed several scripts using the command line in windows (which is needed because there are several 'say' comments that need to be shown) and using the line:

perl "D:/path to script"

That's all fine. But ...

This morning I created a series of shortcuts on Windows, the basic idea being they can click on the icon, and the CMD will open and start running the script. THAT is where I'm stuck !

In the target attribute of the shortcut, I have put:

C:/system32/cmd.exe D:/path to perl script

That opens the command line, and sets the prompt to "D:/path to script_" (I also tried adding perl in between the two arguemennts as per when typing directly into window. That had no effect) I tried "perl D:/path to script" in quotes. That didn't work

I then wondered about batch files, but they appears to close the window once batch has run, so won't be able to display the say commands!

I have also heard of "pl2bat", but no idea if that would keep the CLI alive whilst rest of program run.

This is running client side, and NOT in browser, or sending data to a server, the idea being with Perl on a USB stick, it will be 'self contained' with nothing being installed on PC

  • Try entering target command of a shortcut in an open cmd window. Then you could view result/error message(s) immediately after pressing the <Enter> key.
    – JosefZ
    Mar 10, 2019 at 11:49
  • What I've got so far using the shortcut is Target CMD.exe, Open in "D:\...." That does as expected, and opens the command line with D\ path to script ... but still no execution Mar 10, 2019 at 14:31

2 Answers 2


In general, anything you put as the target in a shortcut can also be run on the command line, and vice versa.

You could have a command that runs <path-to-perl>\perl.exe <full-path-to-pl-script>. Notice there is no reference to cmd.exe. This command can be run directly at a command prompt, or it can be pasted into a batch file, or it can be the target of a shortcut. It can even be used in a Windows Scheduled Task!

If you want more commands executed, such as pausing after the perl script, use something like this: cmd /c "<path-to-perl>\perl.exe <full-path-to-pl-script> & pause" or like this: cmd /k "<path-to-perl>\perl.exe <full-path-to-pl-script>".

But you don't need to use 'cmd' or 'pause'. You can just have your perl script do as the last line. But you also want to print output to STDERR or include this at the top of the pl script $| = 1;. If you let Perl do it's output buffering by default on STDOUT, you won't see some of the output until after hitting ENTER.

use strict; use warnings; $| = 1;
print "some info\n";
foreach my $infoline (@infolines) { print "$infoline\n"; }
print "hit ENTER to continue ";

Back to your starting example, where you say opens the command line, and sets the prompt to "D:/path to script_", that's actually a problem. The shortcut should just directly start the perl script, and for the perl script the starting directory is the "Start in" value from the shortcut. Use chdir to change from there if needed. My advice is to give the perl script full control, including what directory to use, and ignore whatever that starting directory is from the shortcut.


You should be able to do this with a standard .BAT file containing the perl script. To preserve the CMD window put the pause command after the perl script.

D:/path to perl script


  • Forgive my ignorance, John. So the bat file is simply a txt file listing the script path, and pause at end to stop if from closing. But how do I link to that from the shortcut as the "Start in" will only take a folder name. Do I need to modify the line that calls "...cmd.exe" Or is that line itself the call to the batch file? (Have managed to find that you can start the CMD to a specific size from shortcut, so that's a help !) Mar 10, 2019 at 14:35
  • Exactly. Simply create a shortcut for the .BAT file. The cmd.exe is implied by the file type. So I don't think you need to worry. I think examining the properties of the shortcut (not the .BAT file) will give you what you need. Mar 10, 2019 at 14:54
  • Sorry for delay in getting back to you; been working on another program, (this one to allow event photographers to hand people a card that sends client to their personal folder on host) Got the admin side done, now got to work on perl / API2 side of things. On the bat side of things, I will -h -s the folder with perl / scripts so they only access the bat files to run things Mar 13, 2019 at 11:19
  • Oh dear ... copy and pasting / moving,did something wrong and now allthe icons have gone.and none of the files work. (Can run the script by entering target in CMD target ... but batch file. (Somewhere someone suggested "%~d0" so batch ran 'drive indepedent') Just realised CMD target starts with a drive letter. If I copy that to another machine with less partitions, that letter will be wrong.So what to do? (Back to "Square One" !!) Mar 30, 2019 at 14:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .