<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Считывание текста из cmd]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=7849</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=7849&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Считывание текста из cmd».]]></description>
		<lastBuildDate>Wed, 05 Dec 2012 16:52:02 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Считывание текста из cmd]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=66664#p66664</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (creature.ws)]]></author>
			<pubDate>Wed, 05 Dec 2012 16:52:02 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=66664#p66664</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Считывание текста из cmd]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=66663#p66663</link>
			<description><![CDATA[<p>спасибо за пример, буду разбираться, правда без комментов новичку сложновато <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></description>
			<author><![CDATA[null@example.com (seemE1y)]]></author>
			<pubDate>Wed, 05 Dec 2012 16:46:02 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=66663#p66663</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Считывание текста из cmd]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=66660#p66660</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Wed, 05 Dec 2012 16:07:08 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=66660#p66660</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Считывание текста из cmd]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=66659#p66659</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (seemE1y)]]></author>
			<pubDate>Wed, 05 Dec 2012 15:54:35 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=66659#p66659</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Считывание текста из cmd]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=66655#p66655</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (creature.ws)]]></author>
			<pubDate>Wed, 05 Dec 2012 14:53:41 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=66655#p66655</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Считывание текста из cmd]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=66654#p66654</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (seemE1y)]]></author>
			<pubDate>Wed, 05 Dec 2012 14:16:46 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=66654#p66654</guid>
		</item>
	</channel>
</rss>
