Sign in to follow this  
Followers 0
t0ddie

getting data from prompt window

10 posts in this topic

i need to know how to get data from a hidden command prompt window, and place it into a variable.


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites



not exactly sure where to look for examples, could you provide one?


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

StdOutRead() or when using the run command, just do *command* > C:\file.txt


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

*done by head maby the \ needs to be opposite*

Run(@comspec & ' \c dir > "C:\file.txt"')

will output the dir command to C:\file.txt

for STD

$v_NETSTAT = Run(@SystemDir & '\netstat.exe', @SystemDir, @SW_HIDE, 2)
    $v_NETSTAT = StdoutRead ($v_NETSTAT)

for example

Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

heres the thing.

im running another program, that makes the command prompt window.

#include <Constants.au3>
$dir = c\:program files\game

$foo = Run($dir & "\showinstalledkey.exe","", $STDERR_CHILD + $STDOUT_CHILD)
sleep(10000)
While 1
    $line = StdoutRead($foo)
    If @error = -1 Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

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

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

and this dont work.

it wont read anything in the window.

the window title is not c:/windows/system32/cmd.exe

its the directory of the program and the program name.

im not running the prompt myself, im just trying to read data from a prompt another program opened.

edit: i took the @sw_hide out of the code cause i was trying to debug it and i wanted to make sure the program was opening.

and for some reason as well, its creating a .txt file on my desktop, which is where i run the script from.

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

The STD I/O parameter is the 4th parameter to Run(), not the third:

$foo = Run($dir & "\showinstalledkey.exe","", $STDERR_CHILD + $STDOUT_CHILD)
...should be...

$foo = Run($dir & "\showinstalledkey.exe",$dir ,@SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Edited by DaveF

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

hitting self over head.. yeah i figured that out before i read this post, but your right.

and i kinda got something working BUT

im having a serious problem though,

i need to get lines 9 and 10 from the command prompt.

heres what the code looks like that im using.

#include <GuiConstants.au3>
#include <GuiConstants.au3>
#include <Constants.au3>
$dir = c:\
GuiCreate("GUI")
$hEdit = GuiCtrlCreateEdit("", 5, 5, 300, )
$hInput = GUICtrlCreateInput("", 5,220)
GuiSetState()
    $PID = Run($dir & "\showinstalledkey.exe", $dir, @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)
    $origkey = FileOpen(@ScriptDir & "\key.txt",1)


While 1
; Check how many characters are waiting to be read
   $data = StdoutRead($PID, 0, 1)
   If $data Then
      While 1
         $line = StdoutRead($PID)
         If @error = -1 Then ExitLoop
         GUICtrlSetData($hEdit, $line, 1)
                  FileWrite($origkey,$line)
      Wend
   EndIf
  
   $nMsg = GuiGetMsg()
   Select
      Case $nMsg = $GUI_EVENT_CLOSE
         ProcessClose($PID)
         Exit
   EndSelect
WEnd

im having MULTIPLE problems

i have to use sw_show and cant use hide or it wont work.

i run from the script the program that brings up the command prompt. its now bringing up a BLANK command prompt unlike when i start the program manually it shows the data in the command prompt..

i close the command prompt and only THEN does it show the data in the gui and the text file is blank.

i glose the gui and finally its in the .txt file

i tried a crappy workaround to automate this all but none are working.

so my goal is to hide the window, not use a gui at all. and just run my script.

then it will close itself when finished and ill be left with a .txt file containing line 9 from the command prompt, and line 10 from the command prompt.

this is really frustrating me!

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

hitting self over head.. yeah i figured that out before i read this post, but your right.

and i kinda got something working BUT

im having a serious problem though,

i need to get lines 9 and 10 from the command prompt.

heres what the code looks like that im using.

#include <GuiConstants.au3>
#include <GuiConstants.au3>
#include <Constants.au3>
$dir = c:\
GuiCreate("GUI")
$hEdit = GuiCtrlCreateEdit("", 5, 5, 300, )
$hInput = GUICtrlCreateInput("", 5,220)
GuiSetState()
    $PID = Run($dir & "\showinstalledkey.exe", $dir, @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)
    $origkey = FileOpen(@ScriptDir & "\key.txt",1)
While 1
; Check how many characters are waiting to be read
   $data = StdoutRead($PID, 0, 1)
   If $data Then
      While 1
         $line = StdoutRead($PID)
         If @error = -1 Then ExitLoop
         GUICtrlSetData($hEdit, $line, 1)
                  FileWrite($origkey,$line)
      Wend
   EndIf
  
   $nMsg = GuiGetMsg()
   Select
      Case $nMsg = $GUI_EVENT_CLOSE
         ProcessClose($PID)
         Exit
   EndSelect
WEnd

im having MULTIPLE problems

i have to use sw_show and cant use hide or it wont work.

i run from the script the program that brings up the command prompt. its now bringing up a BLANK command prompt unlike when i start the program manually it shows the data in the command prompt..

i close the command prompt and only THEN does it show the data in the gui and the text file is blank.

i glose the gui and finally its in the .txt file

i tried a crappy workaround to automate this all but none are working.

so my goal is to hide the window, not use a gui at all. and just run my script.

then it will close itself when finished and ill be left with a .txt file containing line 9 from the command prompt, and line 10 from the command prompt.

this is really frustrating me!

<{POST_SNAPBACK}>

This is really inelegant, but it works with a Win2K command prompt window. It calls the built-in SelectAllCopy function and puts the clipboard into $var. You can then look for stringinstr to find what you need. May not work with your hidden command window though:

WinActivate("Command Prompt")
send ("!{space}es")
send("{enter}")
$var = ClipGet()
MsgBox(0,"",$var)

Please provide feedback if I did not submit this properly. :">


...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

Share this post


Link to post
Share on other sites

i would rather use something more reliable, and also work on more windows version.

but thanks for the response


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

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