<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: работа с консольными утилитами и командами]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=11587&amp;type=atom" />
	<updated>2016-05-15T07:26:52Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=11587</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: работа с консольными утилитами и командами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103787#p103787" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Drugoy пишет:</cite><blockquote><p>2. можно ли как-то просто избавиться от текста, не относящегося к output? Т.е. вырезать cmd&#039;шное приветствие (&quot;Microsoft Windows … (c) Корпорация Майкрософт … Все права защищены.&quot;), prompt (&quot;C:\path\to\script.ahk\&gt;&quot;) и input (т.е. отправляемые команды)?</p></blockquote></div><div class="codebox"><pre><code>cmd /q /k echo off</code></pre></div>]]></content>
			<author>
				<name><![CDATA[shiz]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26249</uri>
			</author>
			<updated>2016-05-15T07:26:52Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103787#p103787</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: работа с консольными утилитами и командами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103784#p103784" />
			<content type="html"><![CDATA[<p>1. В описаниях говорится, что этот параметр может быть нулём только в случае асинхронного чтения или записи, а здесь синхронное. Так что хотя и не используется, но приходится указывать.</p><p>2. Простого способа, видимо, нет. Команды из вывода cmd.exe можно исключить параметром /q, но всё остальное остаётся. Содержимое вывода зависит от запускаемой программы, поэтому встроить в саму функцию какой-то один для всех парсер нет возможности. Придётся фильтровать уже на выходе функции.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2016-05-15T02:32:33Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103784#p103784</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: работа с консольными утилитами и командами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103777#p103777" />
			<content type="html"><![CDATA[<p><strong>YMP</strong>, благодарю, вроде подходит, но есть пара вопросов:</p><p>1. у вас там в коде есть переменная &quot;BytesWritten&quot;, которая указана всего однажды - она точно нужна?<br />2. можно ли как-то просто избавиться от текста, не относящегося к output? Т.е. вырезать cmd&#039;шное приветствие (&quot;Microsoft Windows … (c) Корпорация Майкрософт … Все права защищены.&quot;), prompt (&quot;C:\path\to\script.ahk\&gt;&quot;) и input (т.е. отправляемые команды)? Хочется чистого output&#039;а, не хочется вручную парсить текущую выдачу.</p>]]></content>
			<author>
				<name><![CDATA[Drugoy]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27463</uri>
			</author>
			<updated>2016-05-14T20:36:30Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103777#p103777</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: работа с консольными утилитами и командами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103763#p103763" />
			<content type="html"><![CDATA[<p>Вот ещё вариант: <a href="http://forum.script-coding.com/viewtopic.php?id=3467">AHK: Запуск консольного приложения с перехватом его ввода и вывода</a>.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2016-05-14T03:02:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103763#p103763</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: работа с консольными утилитами и командами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103762#p103762" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>чем их разделять</p></blockquote></div><p> Обычно &amp;&amp;. Остальное только в вск смогу посмотреть.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2016-05-14T01:38:10Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103762#p103762</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: работа с консольными утилитами и командами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103759#p103759" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong><br />и ещё: команда &quot;type aa.txt&gt;bb.txt&quot; не отрабатывает (должно происходить копирование текстового содержимого файла в другой).</p>]]></content>
			<author>
				<name><![CDATA[Drugoy]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27463</uri>
			</author>
			<updated>2016-05-13T20:51:31Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103759#p103759</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: работа с консольными утилитами и командами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103758#p103758" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong>, спасибо, да, так работает.<br />Не очень понял когда требуется &quot;cmd /c&quot; а когда оно не обязательно.</p><p>И ещё: умеет ли эта функция выполнять несколько команд подряд? Если да - то чем их разделять (попробовал `n - не помогло)?</p>]]></content>
			<author>
				<name><![CDATA[Drugoy]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27463</uri>
			</author>
			<updated>2016-05-13T19:49:53Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103758#p103758</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: работа с консольными утилитами и командами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103757#p103757" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code> MsgBox, % CMDret(&quot;cmd /c echo abc&quot;)</code></pre></div><p> Как-то так, без компа сейчас.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2016-05-13T19:31:53Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103757#p103757</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: работа с консольными утилитами и командами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103756#p103756" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong>, посмотрел, оно выдаёт пустоту в ответ на аргумент &quot;echo abc&quot;.</p>]]></content>
			<author>
				<name><![CDATA[Drugoy]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27463</uri>
			</author>
			<updated>2016-05-13T19:28:34Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103756#p103756</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: работа с консольными утилитами и командами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103739#p103739" />
			<content type="html"><![CDATA[<p>Посмотрите <a href="http://forum.script-coding.com/viewtopic.php?pid=66660#p66660">это</a>.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2016-05-13T12:38:41Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103739#p103739</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: работа с консольными утилитами и командами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103737#p103737" />
			<content type="html"><![CDATA[<p>Необходима универсальная функция для всех версий ahk (a32, u32, u64), которая бы позволяла последовательно выполнять одну или несколько консольных команд или утилит и получать их StdOut (или если он пуст, то - StdErr) в переменную, причём так, чтобы окно консоли не появлялось ни на долю секунды.</p><p>В файле справки на странице о команде run есть такой код:<br /></p><div class="codebox"><pre><code>RunWaitMany(commands) {
    shell := ComObjCreate(&quot;WScript.Shell&quot;)
    ; Open cmd.exe with echoing of commands disabled
    exec := shell.Exec(ComSpec &quot; /Q /K echo off&quot;)
    ; Send the commands to execute, separated by newline
    exec.StdIn.WriteLine(commands &quot;`nexit&quot;)  ; Always exit at the end!
    ; Read and return the output of all commands
    return exec.StdOut.ReadAll()
}</code></pre></div><p>Но с ним появляется окно консоли.</p><p>Товарищ с irc-канала дал такой код:<br /></p><div class="codebox"><pre><code>RunWaitOne(command) {
	WinGet,pid,pid,ahk_id%A_ScriptHwnd%
	DetectHiddenWindows, on
	Run,%comspec% /k,,Hide UseErrorLevel, cPid
	WinWait, ahk_pid %cPid%,,10
	DllCall(&quot;AttachConsole&quot;,&quot;uint&quot;,cPid),hCon:=DllCall(&quot;CreateFile&quot;,&quot;str&quot;,&quot;CONOUT$&quot;,&quot;uint&quot;,0xC0000000,&quot;uint&quot;,7,&quot;uint&quot;,0,&quot;uint&quot;,3,&quot;uint&quot;,0,&quot;uint&quot;,0),shell:=ComObjCreate(&quot;WScript.Shell&quot;),exec:=shell.Exec(command),DllCall(&quot;CloseHandle&quot;,&quot;uint&quot;,hCon),DllCall(&quot;FreeConsole&quot;)
	if(info:=exec.Stderr.ReadAll()){
		return info
	}else{
		return exec.stdout.ReadAll()
	}
}</code></pre></div><p>Но он у меня (на u64) выдаёт ошибку (это даже если код не менять, ведь он заточен под выполнение только одной команды, а не нескольких).</p><p>Пробовал искать по ключевому запросу &quot;autohotkey DllCall AttachConsole&quot; - и <a href="http://forum.script-coding.com/viewtopic.php?id=5650&amp;p=2">нашёлся</a> код с этого форума где используется </p><div class="codebox"><pre><code>DllCall(&quot;AttachConsole&quot;, &quot;Ptr&quot;</code></pre></div><p> вместо </p><div class="codebox"><pre><code>DllCall(&quot;AttachConsole&quot;,&quot;UInt&quot;</code></pre></div><p>, в другом месте нашёлся вариант и <a href="https://github.com/joedf/LibCon.ahk/blob/master/LibCon.ahk">такой вариант</a> использования: </p><div class="codebox"><pre><code>DllCall(&quot;AttachConsole&quot;, &quot;UInt&quot;, cPID, &quot;Cdecl int&quot;)</code></pre></div><p>, а где-то и <a href="https://gist.github.com/renz45/7d19427cd3e498fdcce3">такой</a>: </p><div class="codebox"><pre><code>    
DllCall(&quot;AttachConsole&quot;, int, -1, int)</code></pre></div><p>, а ещё есть вариант от самого lexikos&#039;а, но там код старый и уж больно много его.</p><p>Другими словами - я окончательно запутался и хочу один рабочий код.<br />Умеющие транслировать WinAPI в DllCallы - подсобите, пожалуйста.</p>]]></content>
			<author>
				<name><![CDATA[Drugoy]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27463</uri>
			</author>
			<updated>2016-05-13T12:32:24Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103737#p103737</id>
		</entry>
</feed>
