<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Считывание текста из cmd]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=7849&amp;type=atom" />
	<updated>2012-12-05T16:52:02Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=7849</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Считывание текста из cmd]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66664#p66664" />
			<content type="html"><![CDATA[<p>Комментарий:<br />Функция CMDret возвращает «результат выполнения» консольной команды переданной в виде строки в качестве параметра.<br />Разбираться нет необходимости, достаточно использовать.</p><p>Тот же код:<br /></p><div class="codebox"><pre><code>msgbox % CMDret(&quot;ping ya.ru&quot;)

CMDret(sCmd)
{
    DllCall(&quot;CreatePipe&quot;, &quot;Ptr*&quot;, hStdInRd, &quot;Ptr*&quot;, hStdInWr, &quot;Uint&quot;, 0, &quot;Uint&quot;, 0)
    DllCall(&quot;CreatePipe&quot;, &quot;Ptr*&quot;, hStdOutRd, &quot;Ptr*&quot;, hStdOutWr, &quot;Uint&quot;, 0, &quot;Uint&quot;, 0)
    DllCall(&quot;SetHandleInformation&quot;, &quot;Ptr&quot;, hStdInRd, &quot;Uint&quot;, 1, &quot;Uint&quot;, 1)
    DllCall(&quot;SetHandleInformation&quot;, &quot;Ptr&quot;, hStdOutWr,&quot;Uint&quot;, 1, &quot;Uint&quot;, 1)

    if A_PtrSize = 4
    {
        VarSetCapacity(pi, 16, 0)
        siSize := VarSetCapacity(si, 68, 0)
        NumPut(siSize, si, 0, &quot;UInt&quot;)
        NumPut(0x100, si, 44, &quot;UInt&quot;)
        NumPut(hStdInRd , si, 56, &quot;Ptr&quot;)
        NumPut(hStdOutWr, si, 60, &quot;Ptr&quot;)
        NumPut(hStdOutWr, si, 64, &quot;Ptr&quot;)
    }
    else if A_PtrSize = 8
    {
        VarSetCapacity(pi, 24, 0)
        siSize := VarSetCapacity(si, 96, 0)
        NumPut(siSize, si, 0, &quot;UInt&quot;)
        NumPut(0x100, si, 60, &quot;UInt&quot;)
        NumPut(hStdInRd , si, 80, &quot;Ptr&quot;)
        NumPut(hStdOutWr, si, 88, &quot;Ptr&quot;)
        NumPut(hStdOutWr, si, 96, &quot;Ptr&quot;)
    }

    DllCall(&quot;CreateProcess&quot;
        , &quot;Uint&quot;, 0
        , &quot;Ptr&quot;, &amp;sCmd
        , &quot;Uint&quot;, 0
        , &quot;Uint&quot;, 0
        , &quot;Int&quot;, true
        , &quot;Uint&quot;, 0x08000000
        , &quot;Uint&quot;, 0
        , &quot;Uint&quot;, 0
        , &quot;Ptr&quot;, &amp;si
        , &quot;Ptr&quot;, &amp;pi)

    DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, NumGet(pi, 0))
    DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, NumGet(pi, A_PtrSize))
    DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, hStdOutWr)
    DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, hStdInRd)
    DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, hStdInWr)

    VarSetCapacity(sTemp, 4095)

    while DllCall(&quot;Kernel32.dll\ReadFile&quot;, &quot;Uint&quot;, hStdOutRd, &quot;Ptr&quot;, &amp;sTemp, &quot;Uint&quot;, 4095, &quot;UintP&quot;, nSize, &quot;Uint&quot;, 0)
        sOutput := sOutput . StrGet(&amp;sTemp, nSize, &quot;CP866&quot;)

    DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, hStdOutRd)

    return sOutput
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[creature.ws]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26105</uri>
			</author>
			<updated>2012-12-05T16:52:02Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66664#p66664</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Считывание текста из cmd]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66663#p66663" />
			<content type="html"><![CDATA[<p>спасибо за пример, буду разбираться, правда без комментов новичку сложновато <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[seemE1y]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=29227</uri>
			</author>
			<updated>2012-12-05T16:46:02Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66663#p66663</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Считывание текста из cmd]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66660#p66660" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>seemE1y пишет:</cite><blockquote><p>p.s. если нужно юзать winapi, задумываюсь, а стоит ли тогда на хоткее писать</p></blockquote></div><p>Без знания winapi на &quot;хоткее&quot; далеко не уедешь.<br /></p><div class="codebox"><pre><code>CMDret(sCmd)
{
; http://www.autohotkey.com/community/viewtopic.php?f=2&amp;t=16823  StdoutToVar_CreateProcess(sCmd, bStream=&quot;&quot;, sDir=&quot;&quot;, sInput=&quot;&quot;)
/*
    Пример использования:
    MsgBox, % CMDret(&quot;cmd /c cd&quot;)
*/
   
   DllCall(&quot;CreatePipe&quot;,&quot;Ptr*&quot;,hStdInRd
                       ,&quot;Ptr*&quot;,hStdInWr
                       ,&quot;Uint&quot;,0
                       ,&quot;Uint&quot;,0)
   DllCall(&quot;CreatePipe&quot;,&quot;Ptr*&quot;,hStdOutRd
                       ,&quot;Ptr*&quot;,hStdOutWr
                       ,&quot;Uint&quot;,0
                       ,&quot;Uint&quot;,0)
   DllCall(&quot;SetHandleInformation&quot;,&quot;Ptr&quot;,hStdInRd
                                ,&quot;Uint&quot;,1
                                ,&quot;Uint&quot;,1)
   DllCall(&quot;SetHandleInformation&quot;,&quot;Ptr&quot;,hStdOutWr
                                ,&quot;Uint&quot;,1
                                ,&quot;Uint&quot;,1)

   if A_PtrSize=4
      {
      VarSetCapacity(pi, 16, 0)
      sisize:=VarSetCapacity(si,68,0)
      NumPut(sisize,    si,  0, &quot;UInt&quot;)
      NumPut(0x100,     si, 44, &quot;UInt&quot;)
      NumPut(hStdInRd , si, 56, &quot;Ptr&quot;)
      NumPut(hStdOutWr, si, 60, &quot;Ptr&quot;)
      NumPut(hStdOutWr, si, 64, &quot;Ptr&quot;)
      }
   else if A_PtrSize=8
      {
      VarSetCapacity(pi, 24, 0)
      sisize:=VarSetCapacity(si,96,0)
      NumPut(sisize,    si,  0, &quot;UInt&quot;)
      NumPut(0x100,     si, 60, &quot;UInt&quot;)
      NumPut(hStdInRd , si, 80, &quot;Ptr&quot;)
      NumPut(hStdOutWr, si, 88, &quot;Ptr&quot;)
      NumPut(hStdOutWr, si, 96, &quot;Ptr&quot;)
      }

   DllCall(&quot;CreateProcess&quot;, &quot;Uint&quot;, 0
                           , &quot;Ptr&quot;, &amp;sCmd
                          , &quot;Uint&quot;, 0
                          , &quot;Uint&quot;, 0
                           , &quot;Int&quot;, True
                          , &quot;Uint&quot;, 0x08000000
                          , &quot;Uint&quot;, 0
                          , &quot;Uint&quot;, 0
                           , &quot;Ptr&quot;, &amp;si
                           , &quot;Ptr&quot;, &amp;pi)

   DllCall(&quot;CloseHandle&quot;,&quot;Ptr&quot;,NumGet(pi,0))
   DllCall(&quot;CloseHandle&quot;,&quot;Ptr&quot;,NumGet(pi,A_PtrSize))
   DllCall(&quot;CloseHandle&quot;,&quot;Ptr&quot;,hStdOutWr)
   DllCall(&quot;CloseHandle&quot;,&quot;Ptr&quot;,hStdInRd)
   DllCall(&quot;CloseHandle&quot;,&quot;Ptr&quot;,hStdInWr)

   VarSetCapacity(sTemp,4095)
   nSize:=0
   loop
      {
      result:=DllCall(&quot;Kernel32.dll\ReadFile&quot;, &quot;Uint&quot;, hStdOutRd
                                             ,  &quot;Ptr&quot;, &amp;sTemp
                                             , &quot;Uint&quot;, 4095
                                             ,&quot;UintP&quot;, nSize
                                              ,&quot;Uint&quot;, 0)
      if (result=&quot;0&quot;)
         break
      else
         sOutput:= sOutput . StrGet(&amp;sTemp,nSize,&quot;CP866&quot;)
      }

   DllCall(&quot;CloseHandle&quot;,&quot;Ptr&quot;,hStdOutRd)
   Return,sOutput
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2012-12-05T16:07:08Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66660#p66660</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Считывание текста из cmd]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66659#p66659" />
			<content type="html"><![CDATA[<p>Оу, всё немного сложнее, чем я думал <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />Но пинг яндекса я взял в качестве примера. Истинной целью является именно возврат значения из cmd в переменную для дальнейших манипуляций с этим значением.<br />Подробнее: по одному жмяканью кнопки - телнет на управляемый свич, прописывание нужных команд, считывание результата выполнения команд в переменные, некий анализ содержимого переменных и вывод в msgbox`е результата анализа.&nbsp; Такая вот автоматизированная минидиагностика.<br />p.s. если нужно юзать winapi, задумываюсь, а стоит ли тогда на хоткее писать..</p>]]></content>
			<author>
				<name><![CDATA[seemE1y]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=29227</uri>
			</author>
			<updated>2012-12-05T15:54:35Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66659#p66659</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Считывание текста из cmd]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66655#p66655" />
			<content type="html"><![CDATA[<p>Лыжи не едут потому, что из окна консоли нельзя прочитать текст использованием WinGetText <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />Если цель — узнать, пингуется ли ya.ru, то уместнее воспользоваться примером:<br /></p><div class="codebox"><pre><code>Msgbox % Ping(&quot;ya.ru&quot;)

Ping(host) {
    (ComObjGet(&quot;winmgmts:&quot;).ExecQuery(&quot;Select StatusCode From Win32_PingStatus where Address = &#039;&quot; . host . &quot;&#039;&quot;)._NewEnum)[objStatus]
    return !objStatus.StatusCode
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[creature.ws]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26105</uri>
			</author>
			<updated>2012-12-05T14:53:41Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66655#p66655</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Считывание текста из cmd]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66654#p66654" />
			<content type="html"><![CDATA[<p>Приветствую!</p><p>По примеру из документации <a href="http://www.script-coding.com/AutoHotkey/WinGetText.html">http://www.script-coding.com/AutoHotkey/WinGetText.html</a> пытаюсь вывести текст из cmd. Код таков:</p><div class="codebox"><pre><code>
!h::
Run, cmd
WinWait, C:\
sendinput, ping ya.ru {enter}
WinGetText, text
MsgBox, The text is:`n%text%
return</code></pre></div><p>Но на выходе получаю окно с &quot;The text is&quot; и пустым значением переменной. <br /><span class="postimg"><img src="http://ipic.su/img/img7/fs/kiss_4kb.1354716963.png" alt="http://ipic.su/img/img7/fs/kiss_4kb.1354716963.png" /></span><br />Подскажите пожалуйста, почему лыжи не едут?</p>]]></content>
			<author>
				<name><![CDATA[seemE1y]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=29227</uri>
			</author>
			<updated>2012-12-05T14:16:46Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66654#p66654</id>
		</entry>
</feed>
