in reply to SEQUENTIAL REBOOT ORDER WINDOW$

It would be helpful if you could post some code that I'm able to run on my single Win10 machine.

Perhaps I'm not totally understanding this 2>&1 part of my qx, can I read this output within the script?
This is a very standard command line syntax that redirects both the STDERR and STDOUT filehandles to the same output stream. This works on Unix and on Windows.

On Windows, you can open a pipe to an external program, just like in Unix:

#!/usr/bin/perl use strict; use warnings; open TASK, "tasklist 2>&1|" or die "cannot open pipe to tasklist"; while (<TASK>) { print; }
Again, it would be helpful if you could "dumb down" the example to something that the Monks with Windows can run.
tasklist is a standard Windows command line program that I believe you can run.

Replies are listed 'Best First'.
Re^2: SEQUENTIAL REBOOT ORDER WINDOW$
by 3dbc (Monk) on Jan 26, 2018 at 15:14 UTC
    That worked, now I just need to grep "invalid" within $_ and kill the perl script if it encounters an error with the reboots. When I redo the code, I'll post it here, but you definitely helped move me in the right direction. Thanks.
    - 3dbc
      updated the foreach section, you might have to move around some of the comments because I was experimenting with other commands like ipconfig to see if I can parse the output of a remote machine, which i can ;-) thankfully due to this post kicking my ass in the right direction!:
      sub getDOS { print "This is dollar 0 $_[0]\n\n"; open TASK, "$_[0] 2>&1|" or die "cannot open pipe to DOS"; my @return; while (<TASK>) { #chomp; #chop; #print; #return $_; push @return, $_; } return @return; } foreach (@servers){ my $externalExe = qq(psexec.exe \\\\$_ -u ); $externalExe .= $dev_cred . " -p "; #$externalExe .= $prod_pass . ' -i -d cmd /c shutdown /r /f /t 0'; $externalExe .= $dev_pass . ' ipconfig'; print "\n\n... Program START: \n\n $externalExe \n \n"; my @output = getDOS($externalExe); print "\n\nReturned output from DOS command:\n"; foreach(@output){ print; die if $_ =~ /$[Ee]rror/; die if $_ =~ /[Ii]nvalid/; } #wmic process call create "cmd /C > C:\temp\test.txt 2>&1 netstat. +exe -ano" #PsExec v2.2 - Execute processes remotely #Copyright (C) 2001-2016 Mark Russinovich #Sysinternals - www.sysinternals.com #The handle is invalid. #Error communicating with PsExec service on PR0235IPRT002: #print for qx|$externalExe 2>&1|; # Executes the program, and prin +ts it's output print "\n\n.... run complete ...\n"; sleep 360; }


      next goal is to make this asynchronous and get rid of the sleep command in the loop. I'm going to build in pings / and more psexec's where I parse the output to ensure the server is up before moving onto the next. Also going to include some net server stop commands to more gracefully stop some of the services before doing a forced shutdown.
      - 3dbc
        I know I'm virtually writing to myself, but still able to get a few votes so hopefully some win32 monks are following along, otherwise I'll spawn a new thread. Starting to notice that my psexec approach to run a forced shutdown isn't always going through, because when I run a
        wmic os get lastbootuptime
        doesn't list the current date / time even after successfully triggering a psexec forced reboot over 6 min prior to checking. ie.:
        psexec.exe \\host-u domain\japh -p obfuscate -i -d cmd /c shutdown /r +/f /t 0
        Returns:
        PsExec v2.2 - Execute processes remotely Copyright (C) 2001-2016 Mark Russinovich Sysinternals - www.sysinternals.com Starting cmd on perlhost...n perlhost... cmd started on perlhost with process ID 9088.
        but perhaps my psexec syntax is off or else I should be using another method to remotely force shutdown of windows servers.
        - 3dbc