Jump to content

StdOutRead from Psexec Batch file


Puck
 Share

Recommended Posts

I am trying to grab the output from a batch file run by psexec on a remote computer.

This works

#include <Constants.au3>
$foo = Run("psexec \\servername ipconfig", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
   While 1
      $line = StdoutRead($foo)
      If @error Then ExitLoop
         ConsoleWrite($line)  
   WEnd
      While 1
      $line = StderrRead($foo)
      If @error Then ExitLoop
         ConsoleWrite($line)
   WEnd

But if i create a batch file with 'ipconfig' in it if hangs. Is it possible to grab the output of psexec if it runs a batch file?

Any input would be appreciated.

Link to comment
Share on other sites

  • Moderators

Hi, Puck. Have you taken a look at your batch file? If you just put IPConfig in the batch file, the batch file itself will fall into a continuous loop (in XP anyway). You have to use "IPConfig.exe" in the batch file to get it to work. The following works just fine for me (obviously change the name from my XP VM):

Batch file

ipconfig.exe

Script

#include <Constants.au3>
$foo = Run('C:psexec.exe -i JLVMXP-Altiris "C:ipconfig.bat"', @ScriptDir, @SW_HIDE, $STDERR_MERGED)
   While 1
      $line = StdoutRead($foo)
      If @error Then ExitLoop
         ConsoleWrite($line)
   WEnd
      While 1
      $line = StderrRead($foo)
      If @error Then ExitLoop
         ConsoleWrite($line)
   WEnd
Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I'm guessing you're batch file is trying to run ipconfig without an extension? If so, it's just running itself.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Getting closer. I added the -i parameter and now I get StdErr but no StdOut. here is my exact command. I am forcing a copy of the bat file to the server.

#include <Constants.au3>
$foo = Run("psexec -i \\myserver.somewhere.net -c -f ip.bat", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
                  While 1
        $line = StdoutRead($foo)
        If @error Then ExitLoop
                    ConsoleWrite($line)  
                  WEnd
      While 1
         $line = StderrRead($foo)
         If @error Then ExitLoop
                     ConsoleWrite($line)
                  WEnd
Link to comment
Share on other sites

Change the WorkingDir to "" and see if that has any effect.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

I personally find the copy function of psexec somewhat "iffy" Try just copying the file yourself at the start of the script.

FileCopy("C:ipconfig.bat", "myserver.somewhere.netC$", 1)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Change the WorkingDir to "" and see if that has any effect.

Ok, tried that with same results. If I use psexec parameter '-i' it completes but only StdErr. If I dont use '-i' it just hangs.

Link to comment
Share on other sites

What's in the batch file?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I personally find the copy function of psexec somewhat "iffy" Try just copying the file yourself at the start of the script.

FileCopy("C:ipconfig.bat", "myserver.somewhere.netC$", 1)

I tried to put the file there first but still same issue. If I remove the flags for $STDERR_MERGED everythign works fine in the child window. I am sure I am missing something simple just cant pinpoint it.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...