Показать полную графическую версию : [решено] StdOutRead и ShellExecute
ShogenOFF
12-08-2010, 12:40
Есть консольная прога, которая запускается с параметрами с помощью ShellExecute(). В справке написано, что StdOutRead только для запуска с помощью Run(). Вопрос: как получить выдачу(по-моему эт так называется) консоля, т.е. то, что отображается на экране, eсли запущен процесс ShellExecute'ом?
ShogenOFF, запускать Run'ом?
Microteam
12-08-2010, 16:25
Да я понял ваш вопрос поробуйте с помощью ConsoleRead()
ShogenOFF
12-08-2010, 16:32
Не понял.....Мне нужно запустить консльную прогу с параметрами и с выводом выдачи консоля
ShogenOFF, любую программу запущенную ShellExecute'ом можно запустить Run'ом
madmasles
12-08-2010, 17:43
ShogenOFF,
Попробуйте так:#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <Constants.au3>
;#include <Encoding.au3>
$sLog = ''
$hIPconfig = Run (http://www.autoitscript.com/autoit3/docs/functions/Run.htm)('IPCONFIG /?', '', @SW_HIDE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_hide), $STDOUT_CHILD)
;$hIPconfig = Run(@ComSpec & ' /C IPCONFIG /?', '', @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)($hIPconfig)
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)
;$sLog = _Encoding_866To1251($sLog)
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(0, '', $sLog)Поменяйте IPCONFIG на Вашу консольную программу, /? - на Ваши параметры, , '', - на Вашу рабочую директорию. На всякий случай: Encoding UDF (http://autoit-script.ru/index.php/topic,510.0.html). (если будут вылазить кракозябры).
saavaage
14-08-2010, 02:52
madmasles, а если понадобиться вывести данные $sLog не в меседж-бокс, а в GuiEdit, например?
Что-то у меня не выводятся:
********* задание формы и т.д.
$Edit1 = GUICtrlCreateEdit("", 24, 64, 481, 233)
local $sLog = ''
local $hIPconfig = Run(@ComSpec & ' /C CSCRIPT %SYSTEMROOT%\system32\eventquery.vbs /fi "Type eq ERROR" /fo TABLE /NH', '', @SW_HIDE, $STDOUT_CHILD)
While 1
$sLog &= StdoutRead($hIPconfig)
If @error Then ExitLoop
Sleep(10)
WEnd
GUICtrlSetData ($Edit1, _Encoding_866To1251($sLog))
не могу понять, что мешает...
madmasles
14-08-2010, 10:34
не могу понять, что мешает... »
Странно. У меня все выводится, причем с тремя вариантами:#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <Constants.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <Encoding.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("Form1", 623, 445, 192, 124)
$Edit1 = GUICtrlCreateEdit (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateEdit.htm)("", 104, 24, 433, 385)
$sLog = ''
;$hIPconfig = Run(@ComSpec & ' /C CSCRIPT %SYSTEMROOT%\system32\eventquery.vbs /fi "Type eq ERROR" /fo TABLE /NH', '', @SW_HIDE, $STDOUT_CHILD)
$hIPconfig = Run (http://www.autoitscript.com/autoit3/docs/functions/Run.htm)('CSCRIPT.exe ' & @SystemDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@systemdir) & '\eventquery.vbs /fi "Type eq ERROR" /fo TABLE /NH', '', @SW_HIDE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_hide), $STDOUT_CHILD)
;$hIPconfig = Run(@ComSpec & ' /C CSCRIPT ' & @SystemDir & '\eventquery.vbs /fi "Type eq ERROR" /fo TABLE /NH', '', @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)($hIPconfig)
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)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($Edit1, _Encoding_866To1251($sLog))
$Button1 = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Обновить", 16, 120, 65, 57)
GUICtrlSetState (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetState.htm)(-1, $GUI_FOCUS)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_show))
#endregion ### END Koda GUI section ###
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$nMsg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $nMsg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $Button1
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($Edit1, '')
$sLog = ''
;$hIPconfig = Run(@ComSpec & ' /C CSCRIPT %SYSTEMROOT%\system32\eventquery.vbs /fi "Type eq ERROR" /fo TABLE /NH', '', @SW_HIDE, $STDOUT_CHILD)
$hIPconfig = Run (http://www.autoitscript.com/autoit3/docs/functions/Run.htm)('CSCRIPT.exe ' & @SystemDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@systemdir) & '\eventquery.vbs /fi "Type eq ERROR" /fo TABLE /NH', '', @SW_HIDE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_hide), $STDOUT_CHILD)
;$hIPconfig = Run(@ComSpec & ' /C CSCRIPT ' & @SystemDir & '\eventquery.vbs /fi "Type eq ERROR" /fo TABLE /NH', '', @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)($hIPconfig)
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)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($Edit1, _Encoding_866To1251($sLog))
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
saavaage
14-08-2010, 12:31
madmasles, проблема, скорее всего, что у меня не одна вкладка и на каждой выполняются функции. Уже не в первый раз такое происходит.
Все, разобрался. Пропустил
#include <Constants.au3>
Показалось, что есть, а на самом деле - не было включено
saavaage
14-08-2010, 12:56
madmasles, не подскажешь как вывод ограничить только нужной информацией. Мне, например, не надо, чтобы выводились эти строки:
Сервер сценариев Windows (Microsoft R) версия 5.7
c Корпорация Майкрософт (Microsoft Corp.), 1996-2001. Все права защищены.
ИНФОРМАЦИЯ: Для журнала 'application' нет записей, отвечающих заданному критерию.
INFO: Нет доступных записей в журнале '%3'.
INFO: Нет доступных записей в журнале '%3'.
Можно сделать, чтобы выводилось, только то, что под ними? Т.е. начало вывода - с полосы
------------------------------------------------------------------------------
На всякий прикрепляю весь полученный вывод:
Сервер сценариев Windows (Microsoft R) версия 5.7
c Корпорация Майкрософт (Microsoft Corp.), 1996-2001. Все права защищены.
ИНФОРМАЦИЯ: Для журнала 'application' нет записей, отвечающих заданному критерию.
INFO: Нет доступных записей в журнале '%3'.
INFO: Нет доступных записей в журнале '%3'.
------------------------------------------------------------------------------
Перечисление событий в журнале 'system' для узла 'CAVE-0001974'
------------------------------------------------------------------------------
ошибка 7011 08.10.2010 18:22:04 Service Control M CAVE-0001974
madmasles
14-08-2010, 13:43
saavaage,
Попробуйте так:GUICtrlSetData($Edit1, StringRegExpReplace(_Encoding_866To1251($sLog), "(?s).*?'%3'.\r\n\s\r\n(.*?)", '\1'))
saavaage
14-08-2010, 13:49
madmasles, отлично. Правда есть сомнения - не лучше ли отграничить именно первой линией --------------------. Этот элемент более постоянный, имхо.
PS Полез смотреть StringRegExpReplace
madmasles
14-08-2010, 14:07
saavaage,
У меня выводится такой текст:Сервер сценариев Windows (Microsoft R) версия 5.7
c Корпорация Майкрософт (Microsoft Corp.), 1996-2001. Все права защищены.
------------------------------------------------------------------------------
Перечисление событий в журнале 'application' для узла 'HOME'
------------------------------------------------------------------------------
ошибка 1103 13.08.2010 9:43:07 .NET Runtime Opti HOME
INFO: Нет доступных записей в журнале '%3'.
------------------------------------------------------------------------------
Перечисление событий в журнале 'system' для узла 'HOME'
------------------------------------------------------------------------------
ошибка 59 08.09.2010 2:33:03 SideBySide HOME и к первой линии не привязаться. (XP SP3 32)
Мне кто нибудь может объяснить, что здесь обсуждается? тема называется «StdOutRead и ShellExecute», этот вопрос решён? мне кажется да, ещё на первой странице.
saavaage
21-08-2010, 06:07
Creat0R, мы немного увлеклись и взглянули на проблему шире... :-)
в принципе, проблема и пример описаны в посте http://forum.oszone.net/post-1478325-24.html
Суть: натолкнулись на проблему ограничения вывода - в ListView не отображается полная строка с описанием ошибки (обрывается на 300 с чем-то знаков). »
Не поможете ее успешно побороть?
PS Судя по всему, придется потом перенести все в отдельную тему....
мы немного увлеклись и взглянули на проблему шире... :-) »
Ну я могу тоже увлечся и начать раздавать баны http://files.myopera.com/Creat0R/Opera_AC/Icons/whistle.gif
проблема и пример описаны в посте »
Отделяю...
Ума не приложу, как назвать тему...
Несколько Вопросов немного не в тему от saavaage (http://forum.oszone.net/showthread.php?t=183492)
Тут больше не пишите.
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.