Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Tk Program Converted to Executable Requires 2 ENTERs to Run

by pryrt (Abbot)
on May 25, 2021 at 14:22 UTC ( [id://11133015]=note: print w/replies, xml ) Need Help??


in reply to Tk Program Converted to Executable Requires 2 ENTERs to Run

I knew I had seen this before, but couldn't remember where or how to fix it.

It seemed similar to stevieb's recent question, but that one was "solved" by the problem not coming back on a new VM.

I can confirm if I copy your Tk script to tk.pk and run it in various ways (even without compiling it to an executable), I can replicate your problem under certain circumstances:

perl tk.pl & rem ok tk.pl & rem ok start perl tk.pl & rem ok start tk.pl & rem ok start /b perl tk.pl & rem requires second ENTER, it is the start /b op +tion that's confusing things start /b tk.pl & rem requires second ENTER, same culprit

But one of the things you're trying to do with start /b is get rid of the command window; perlwin32 #Miscellaneous-Things explains that you should use wperl.exe for that:

start /b wperl tk.pl & rem does not require second ENTER wperl tk.pl & rem does not require start/b and doesn't requir +e a cmd.exe window to be created, even when run from Run dialog or fr +om a file association

With that, you could use a separate extension (maybe .pltk or .tkpl) and associate that extension with wperl.exe instead of perl.exe, and that should work in all locations, without needing to compile to executable, and it will run without having a cmd.exe window opening.

In the Anonymous Monk's shotgun of links, Discipulus had found an old MS KB article 321788, where it points out that it's STDOUT and STDIN causing the problem (which is why wperl gets around it, because those handles aren't used because there's no "console" window for wperl). But that article also shows editing the registry to add a value to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer of InheritConsoleHandles (REG_DWORD) = 1. When I try after the registry fix:

start /b perl tk.pl & rem no longer requires second ENTER after regist +ry fix start /b tk.pl & rem no longer requires second ENTER after regist +ry fix

Oh, right, and pp has the --gui (aka -g) option, which allows for compiling so that it runs without the console. Maybe your compiler has a similar option.

To sum up:

So, if you're using an association and don't want to compile, use wperl for Tk scripts (or Win32::GUI scripts, or anything that doesn't need STDIN/STDOUT/STDERR console).

pp --gui should allow you to make a compiled perl script .exe which runs without opening console, and other compilers may have similar options.

If you want to use a compiled version with your compiler if it doesn't have a similar option, then you can should be able to change the registry as described above, and now start/b should launch the script or the compiled script without a cmd.exe window being created. (Sorry, I don't have your compiler, so I cannot test your exact situation; but since I could replicate without the compiler, and the registry solved the problem, I think it will solve the problem.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11133015]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-18 02:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found