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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automatically close command prompt window 2

Status
Not open for further replies.

nix45

MIS
Nov 21, 2002
478
US
I wrote a Perl script that runs on a Winblows machine that creates an HTML file on the users local hard drive, and then launches their web browser at the end of the script opening the HTML page that was just created. When the script is run, a blank Windows command prompt window opens up and stays open until you close the web browser. Is there any way to suppress this window from ever popping up? I've even created a package out of this script using perl2exe, but the command prompt window still opens and doesn't close until the web browser is closed.

Any ideas?

Thanks,
Chris
 
To see what I'm talking about, just place any .html file at the root of the C: drive and run this simple code...
Code:
#!perl
$ie = '"C:\Program Files\Internet Explorer\iexplore.exe" C:\index.html';
system($ie);
When you run it, you'll see that a command prompt window appears and doesn't close until you close IE (or whatever web browser you are using).

Chris
 
It gave me this error...

Can't call method "start" without a package or object reference at C:\SPAM_L~1.PL line 64.

What does the start function do?

Chris
 
...nevermind, I forgot the quotes, that actually works! What does the 'start' function do?

Thanks chazoid,

Chris
 
no problem.. It just opens another instance of cmd.exe (the command interpreter) which I suppose closes quickly after IE is launched.
For more info, '/?' is the equivalent to --help for most commands:
C:\>start /?

"When executing an application that is a 32-bit GUI application, CMD.EXE
does not wait for the application to terminate before returning to
the command prompt. This new behavior does NOT occur if executing
within a command script."

There are other ways to do this too, I think using Win32::process with the constant CREATE_NEW_CONSOLE is the way to go if you want to capture the exit code/pid etc.
 
One more issue I'm running into. This has nothing to do with the script, but with the windows 'start' command itself. If the path to the HTML file I'm trying to open has spaces in it, I'll get an error. I also realized that you don't have to call IE before the file, you can just call the file itself with the system call...system($file); or system("start $file");.

F:\>start C:\test folder\file.html
The system cannot find the file C:\test.

If you enclose it with quotes, then it doesn't do anything, no error and it just brings you to a blank command prompt window.

F:\>start "C:\test folder\file.html"

F:\>

Anyone have any idea's how I can call this file if there are spaces in the path?

Thanks,
Chris

 
Just quote only what you need to quote...

F:\>start C:\"test folder"\file.html



--
Andy
"Historically speaking, the presence of wheels in Unix has never precluded their reinvention."
Larry Wall
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top