in reply to More Perl/Tk Queries with Spawned Processes under Win32

$ProcessObj->Wait(INFINITE);

a/ Says 'wait for ever or until the process terminates'. That stalls the creating script until the created task completes. Omit the Wait and the creating script will continue to run. You can monitor the state of the created process using the process object.

b/ I don't know

c/ Because the script isn't running until notepad closes the running text doesn't get updated until notepad closes, then gets overwritten anyway.

The following should help sort out the process stuff:

sub myjob2 { Win32::Process::Create(my $ProcessObj, "C:\\windows\\system32\\notepad.exe", "notepad noname.txt", 0, NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport(); my $exitcode; $mw->update () while $ProcessObj->GetExitCode($exitcode), $exitcod +e == 259; print $exitcode; }

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: More Perl/Tk Queries with Spawned Processes under Win32
by ozboomer (Friar) on May 09, 2006 at 03:22 UTC

    This suggestion works very well, with some modifications... many thanks for your help!

    I'm not sure if I should put this next item in another question by itself... but as it's related to the current program...

    It's always a bugbear that when using Win32::Process::Create, complete paths need to be specified in the call, rather than letting the PATH search mechanisms find the program I want to run.

    In the current example, this means we have to specify the call like:

    Win32::Process::Create($ProcessObj, "C:\\windows\\system32\\notepad.exe", "notepad c:\\tmp\\del.me", 0, NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport();

    I'd like to know how people get around this problem, particularly when programs are placed in non-standard locations (although the programs may be found on PATH).

    I've had a look in 'SuperSearch' but had no joy. One thought would be to collect the list of directories in PATH via File::Spec->path() and then use File::Find on the result. Alternatively, there seems to be a module on CPAN called File::PathList which (I think) returns the fully-pathed filespec directly.

    Any other thoughts? ...and many thanks for any forthcoming suggestions :)

      You could allow the shell to do the path resolution for you:

      Win32::Process::Create( $obj, "C:\\windows\\system32\\cmd.exe", 'cmd /c notepad somefile', 0, NORMAL_PRIORITY_CLASS, '.' ) or die $^E;;

      Or more simply use system

      ## Run the command asyncronously with shell command resolution $pid = system 1, 'notepad'; .... ## Do other stuff ## Retrieve the exit code waitpid $pid, 0; print 'command return status: ', $? >> 8;; command return status: 0

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.