Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

start up process without waiting

by exilepanda (Monk)
on Dec 06, 2012 at 15:23 UTC ( #1007604=perlquestion: print w/ replies, xml ) Need Help??
exilepanda has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I am on WinXP, and I want to write a script that able to open files like double-click. However I stuck because I have no way to start the second file until the first file is closed. And since there are multiple files, so I can't use exec() as it will end the script, but system() is not my option either. I also tried `start "file"`, but it just create a empty shell and the file won't open at all. What can I do ?

Comment on start up process without waiting
Download Code
Re: start up process without waiting
by kennethk (Monsignor) on Dec 06, 2012 at 15:29 UTC

    Your problem description is a little obtuse to me; code is worth 1k words. See How do I post a question effectively?.

    One possible solution to your issue as I understand it would be to fork or use threads. Which you pick depends on a lot of particulars of what you intend to do while the files are open and once the files are closed. Using a fork and exec might look like:

    $SIG{CHLD} = "IGNORE"; for my $file (@files) { exec $file unless fork; }

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      alright, thank you...
      thanks for your updated with code demonstration. However I think there's no fork for windows. Anyway, I just resolved this in more shell way:
      `start /B /I "" "$file"`;

        While there is no fork() system call on Windows, your version of perl was likely built to emulate it using threads; thus the code I provided will work -- and was, in fact, tested on a Windows XP machine. See fork, perlfork and/or fork in perlport.


        #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

        Also, as you are tossing away your return values, you should not be using backticks. Not only is your intent misleading, using system also buys you automatic escaping if you use the multiple argument form:

        for $file (@files) { system 'start', '/B', '/I', '', $file }

        #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: start up process without waiting
by Anonymous Monk on Dec 06, 2012 at 16:24 UTC
      BIG THANKS!! This is the missing part that I am looking for! The way I found can only trigger files to open without waiting, but not for executable. This one works perfectly as I needed.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1007604]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-08-29 04:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls