Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tk : Running windows commands without a dosbox 1

Status
Not open for further replies.

Cambridge10

Programmer
May 5, 2008
18
NL
I'm using perl Tk and I have to call a couple of Windows commands but they are executed in a dosbox.

I want to prevent a dosbox is opened or at least hidden for the user. Is there any way to prevent that?

Code:
system ("test.txt|perl prep|afbreek.exe|klank.exe|perl kleur >output.pho"); 
system ("mbrola nl3 output.pho output.wav");
 
Thanks for the fast response
I've read it but it's not exactly what I mean. I'm using wperl.exe myscript.pl
This works fine but when I call a windows command inside myscript.pl a dosbox flashes by and I want to prevent that for the user.
 
iirc this doesn't seem to be possible. I've run into a similar problem in the past with Windows... for example the `start` command always requires a cmd window, but it's so useful for launching web pages... e.g. `start
But when run in wperl.exe it brings up a cmd window until the browser can be awakened to load the page and then the cmd window closes. I've tried all the various ways of running this command...

Code:
system("start [URL unfurl="true"]http://google.com");[/URL]
`start [URL unfurl="true"]http://google.com`;[/URL]
open (CMD, "start [URL unfurl="true"]http://google.com|");[/URL]
open (CMD, "|start [URL unfurl="true"]http://google.com");[/URL]

All these formats require the cmd window to appear until the command finishes.

I've also messed around with Win32::process and its options of allegedly not showing a GUI window for the process it's launching, and never had much luck with that either. It seems like all the built-in Windows commands require a cmd window to be present, and so if there isn't one then it creates one.

On that linked thread there's some code that uses Win32::GUI to hide the current cmd window. You might try using that... invoke your script as normal in a cmd prompt window, and have the script hide the window. Then any shell commands might try to re-use the "existing" window, which is hidden, instead of opening a new window. I haven't tried this yet and can't tell you how well it works.

-------------
Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b";print$i++%2?"/":"_";goto x;'
 
Okay, I've verified that this does work:

Code:
#!/usr/bin/perl

use Win32::GUI;
my $dos = Win32::GUI::GetPerlWindow();
Win32::GUI::Hide($dos);

use Tk;
my $mw = MainWindow->new (
  -title => 'Test',
);

my $but = $mw->Button (
  -text => 'Launch Web',
  -command => sub {
    system("start [URL unfurl="true"]http://google.com");[/URL]
  },
)->pack;

MainLoop;

Note that `start` on a URL will block until the web browser comes up and displays the URL. If your browser isn't running, your program might appear to be frozen for numerous seconds. Don't panic and try to kill it, just be patient until the browser appears. There's a way to use threads and have the system command run in a separate thread so it won't freeze your Tk window, but that's a different topic.

Anyway, this code when run via the command line in the normal "perl test.pl" way, will run the system command without displaying a new cmd window at all.

If you're compiling your script into an EXE, don't check the "GUI" option when compiling it (the GUI option will hide the cmd window to begin with, like wperl.exe, but we need the cmd window to exist so the Perl script can hide it but have it available to Windows to run system commands in).

-------------
Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b";print$i++%2?"/":"_";goto x;'
 
Nice! A star for MoshiachNow! :)

-------------
Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b";print$i++%2?"/":"_";goto x;'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top