Показать полную графическую версию : нужно несколько примеров работы с вводом/выводом консольных программ
crashtuak
29-06-2010, 15:19
Пытался сам разобраться, не вышло считать вывод, и ввести ничего не вышло, прошу дать несколько примеров. Буду благодарен.
madmasles
29-06-2010, 15:54
crashtuak,
Здесь посмотрите: Коммуникация процессов при помощи STDIN/STDOUT (http://autoit-script.ru/index.php?topic=332.0).
Простой пример:
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <Constants.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <Encoding.au3>
$sLog = ''
$mod = Run (http://www.autoitscript.com/autoit3/docs/functions/Run.htm)(@ComSpec (http://www.autoitscript.com/autoit3/docs/macros.htm#@comspec) & " /C tasklist /?", "", @SW_HIDE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_hide), $STDOUT_CHILD)
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$sLog &= StdoutRead (http://www.autoitscript.com/autoit3/docs/functions/StdoutRead.htm)($mod)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(10)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(0, '', _Encoding_866To1251($sLog))
Encoding UDF - Библиотека для работы с кодировками строк (http://autoit-script.ru/index.php?topic=510.0)
crashtuak
30-06-2010, 13:26
madmasles, данный пример комуникации процессов поможет сделать что то на подобии многопоточности(потоков то и вправду будет несколько). Хоть и криво будет, но работает:)
crashtuak
30-06-2010, 17:54
Вот код, который работает не до конца:
#include <Constants.au3>
#include <Encoding.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 633, 418, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 8, 384, 481, 21)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 609, 369)
GUICtrlSetData(-1, "Edit1")
$Button1 = GUICtrlCreateButton("Button1", 496, 384, 121, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
$sLog = ''
$mod = Run("C:\android-sdk-windows\tools\adb.exe", "", @SW_MAXIMIZE , $STDOUT_CHILD)
While 1
$sLog &= StdoutRead($mod)
If @error Then ExitLoop
Sleep(10)
WEnd
GUICtrlSetData ( $Edit1, _Encoding_866To1251($sLog))
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
EndSwitch
WEnd
Нужный текст попросту не выводится в $sLog, но отображается в "отладочном окошке" (не знаю как оно правильно называется, обвел красным прямоугольником:)). Ну и так как в $sLog текст не попал, то и в $Edit1 он не попал тоже... В чем может быть проблема?
http://img707.imageshack.us/img707/7987/58505076.th.jpg (http://img707.imageshack.us/i/58505076.jpg/)
madmasles
30-06-2010, 19:13
crashtuak,
У меня нет этой программы, так что не знаю, как Вам помочь.
crashtuak
01-07-2010, 08:32
madmasles, прошу помочь. adb прикрепил.
crashtuak
01-07-2010, 09:31
Ну и еще один вопросик: почему при $mod = Run("C:\windows\system32\cmd.exe", "C:\windows\system32\", @SW_MAXIMIZE , $STDOUT_CHILD) консоль открывается и сразу закрывается, а при $mod = Run("C:\windows\system32\cmd.exe") остается работать?(но второй вариант неприменим, потому что надо STDOUT_CHILD)
madmasles
01-07-2010, 10:24
crashtuak,
Попробуйте так:#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <Constants.au3>
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $foo = Run (http://www.autoitscript.com/autoit3/docs/functions/Run.htm)(@ComSpec (http://www.autoitscript.com/autoit3/docs/macros.htm#@comspec) & " /c adb.exe", '', @SW_HIDE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_hide), $STDERR_CHILD + $STDOUT_CHILD)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $line
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$line = StdoutRead (http://www.autoitscript.com/autoit3/docs/functions/StdoutRead.htm)($foo)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$line = StderrRead (http://www.autoitscript.com/autoit3/docs/functions/StderrRead.htm)($foo)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(0, "STDERR read:", $line)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
crashtuak
01-07-2010, 10:34
madmasles, оу, спасибо, пашет. Возьму себе на вооружение:если с STDOUT самой проги считать неполучается-считывай с CMD:)
Ой, а про моментальное закрытие консоли я так и не уточнил...
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.
Available in ZeroNet 1osznRoVratMCN3bFoFpR2pSV5c9z6sTC