Sign in to follow this  
Followers 0
Nunos

StdinWrite and StdoutRead question

11 posts in this topic

I am trying to make an input box pop up and ask for a user to enter a url and then pass that to nslookup and read the results that come back and display them. The most recent version is below but I can not get the thing to exit and I am not getting all of the expected returned results. Not sure where I messed this up but if someone will teach me what I did wrong I would appreciate it.

#include 

$NSLookupURL = InputBox("NSLookup", "Enter the URL to perform the Name Server Lookup on.", "www.bing.com")
Local $nslookup = Run(@ComSpec & " /c nslookup", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDERR_MERGED)

StdinWrite($nslookup,$NSLookupURL)
Local $line
While 1
$line = StdoutRead($nslookup)
If @error Then ExitLoop
MsgBox(0, "STDOUT read:", $line)
WEnd

While 1
$line = StderrRead($nslookup)
If @error Then ExitLoop
MsgBox(0, "STDERR read:", $line)
WEnd

MsgBox(0, "Debug", "Exiting...")

Share this post


Link to post
Share on other sites



This code works for me:

#include <Constants.au3>
$NSLookupURL = InputBox("NSLookup", "Enter the URL to perform the Name Server Lookup on.", "www.bing.com")
Local $pid = Run(@ComSpec & " /c nslookup " & $NSLookupURL, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
If @error Then Exit MsgBox(0, "Error", "Error " & @error & " occurred when running NSLOOKUP")
StdinWrite($pid, @CRLF)
StdinWrite($pid)
; STDOUT
$sSTDOUT = ""
While 1
    $sOutput = StdoutRead($pid)
    If @error Then ExitLoop
    If $sOutput <> "" Then $sSTDOUT = $sSTDOUT & @CRLF & $sOutput
WEnd
; STDERR
$sSTDERR = ""
While 1
    $sOutput = StderrRead($pid)
    If @error Then ExitLoop
    If $sOutput <> "" Then $sSTDERR = $sSTDERR & @CRLF & $sOutput
WEnd
ConsoleWrite("STDOut: " & $sSTDOUT & @LF)
ConsoleWrite("STDErr: " & $sSTDERR & @LF)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I'd do it this way myself.

#include <Constants.au3>
Global $OutLine = ""

$NSLookupURL = InputBox("NSLookup", "Enter the URL to perform the Name Server Lookup on.", "www.bing.com")
Local $nslookup = Run(@ComSpec & " /c nslookup", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDERR_MERGED)
Sleep(1000) ; Just in case it needs time to start up
StdinWrite($nslookup, $NSLookupURL & @CRLF) ; Needs the enter key hit before it will process what's on the line
Local $line
StdinWrite($nslookup) ; Close the stream so it reads what you've sent to it.
While 1
    $line = StdoutRead($nslookup)
    If @error Then ExitLoop
    $OutLine &= $line 
WEnd
MsgBox(64, "", $OutLine) ; one message box rather than 100's
$OutLine = ""
While 1
    $line = StderrRead($nslookup)
    If @error Then ExitLoop
    $OutLine &= $line
WEnd
MsgBox(64, "", $OutLine)

MsgBox(0, "Debug", "Exiting...")

I'm not sure your StdInWrite would work for this command, because you never close the stream or send the Enter key after the data.

Edited by BrewManNH

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

Share this post


Link to post
Share on other sites

Awesome thanks for the help!!! I appreciate you taking your time to explain it to me so I can learn better. :D

Share this post


Link to post
Share on other sites

Glad to be of service :D


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Sorry to bring this back up again but I was wondering if there is a way to have a user Copy/Paste the results from the msgbox? I thought if I made it Modal they could copy and paste the results into a chat window but I couldn't. Would I need to get the output into something like a GUI window or something else?

Share this post


Link to post
Share on other sites

You might be able to ClipGet the results and then paste it wherever.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

I am sorry I am not sure if that will allow someone else to copy the results from the msgbox and paste them say into like a chat room window.

Share this post


Link to post
Share on other sites

What I was thinking: use ClipGet in your program, the person running the program can then paste into whatever.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

I will research that some and see if I can make it work thank you for the help.

Share this post


Link to post
Share on other sites

You bet. Hope it helps you out. Good luck.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
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
Sign in to follow this  
Followers 0