<div dir="ltr"><div><div>function CmdExec(Cmd: string): string;<br>{<br>ESTA FUNCION MUESTRA LA SALIDA DE CMD<br>EJEMPLO<br>SHOWMESSAGE(CmdExec(echo hola))<br>}<br>var<br> Buffer: array[0..4096] of Char;<br> si: STARTUPINFO;<br>
sa: SECURITY_ATTRIBUTES;<br> sd: SECURITY_DESCRIPTOR;<br> pi: PROCESS_INFORMATION;<br> newstdin, newstdout, read_stdout, write_stdin: THandle;<br> exitcod, bread, avail: Cardinal;<br>begin<br> Result:= '';<br>
if IsWinNT then<br> begin<br> InitializeSecurityDescriptor(@sd, SECURITY_DESCRIPTOR_REVISION);<br> SetSecurityDescriptorDacl(@sd, true, nil, false);<br> sa.lpSecurityDescriptor := @sd;<br> end<br> else sa.lpSecurityDescriptor := nil;<br>
sa.nLength := sizeof(SECURITY_ATTRIBUTES);<br> sa.bInheritHandle := TRUE;<br> if CreatePipe(newstdin, write_stdin, @sa, 0) then<br> begin<br> if CreatePipe(read_stdout, newstdout, @sa, 0) then<br> begin<br> GetStartupInfo(si);<br>
with si do<br> begin<br> dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;<br> wShowWindow := SW_HIDE;<br> hStdOutput := newstdout;<br> hStdError := newstdout;<br> hStdInput := newstdin;<br>
end;<br> Fillchar(Buffer, SizeOf(Buffer), 0);<br> GetEnvironmentVariable('COMSPEC', @Buffer, SizeOf(Buffer) - 1);<br> StrCat(@Buffer,PChar(' /c ' + Cmd));<br> if CreateProcess(nil, @Buffer, nil, nil, TRUE, CREATE_NEW_CONSOLE, nil, nil, si, pi) then<br>
begin<br> repeat<br> PeekNamedPipe(read_stdout, @Buffer, SizeOf(Buffer) - 1, @bread, @avail, nil);<br> if bread > 0 then<br> begin<br> Fillchar(Buffer, SizeOf(Buffer), 0);<br>
ReadFile(read_stdout, Buffer, bread, bread, nil);<br> Result:= Result + String(PChar(@Buffer));<br> end;<br> Application.ProcessMessages;<br> GetExitCodeProcess(pi.hProcess, exitcod);<br>
until (exitcod <> STILL_ACTIVE) and (bread = 0);<br> end;<br> CloseHandle(read_stdout);<br> CloseHandle(newstdout);<br> end;<br> CloseHandle(newstdin);<br> CloseHandle(write_stdin);<br>
end;<br>end; <br><br><br></div>Como vez alli en la funcion StrCat colocan CMD por lo que asi como esta funciona solo en windows no se si podria funcionar con la consola de linux.<br><br></div>Una Pregunta windows 8 Trae CMD o lo eliminaron totalmente por el nuevo shell<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">El 3 de agosto de 2013 19:52, Martin Gomez <span dir="ltr"><<a href="mailto:mmgomez@gmail.com" target="_blank">mmgomez@gmail.com</a>></span> escribió:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="im"><br><div class="gmail_quote">2013/8/3 metal box <span dir="ltr"><<a href="mailto:metalbox9000@gmail.com" target="_blank">metalbox9000@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Bueno, gracias de todos modos pero me encontre una funcion que obtiene el valor de salida y lo guado desde un memo y al cargar funciona correctamente.</blockquote></div><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">
Y cual sería esa función?</div><div class="gmail_default" style="font-family:tahoma,sans-serif">Yo uso la del ejemplo que envié y me resulta, pero quizás la tuya sea mas simple?</div><span class="HOEnZb"><font color="#888888"><div class="gmail_default" style="font-family:tahoma,sans-serif">
<br></div><br><br clear="all"><div><br></div>-- <br><div><span style="font-family:tahoma,sans-serif">Try not to become a man of success but rather to become a man of value. <i>Albert Einstein</i></span></div>
</font></span></div></div>
<br>_______________________________________________<br>
Lazarus-es mailing list<br>
<a href="mailto:Lazarus-es@lists.lazarus.freepascal.org">Lazarus-es@lists.lazarus.freepascal.org</a><br>
<a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus-es" target="_blank">http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus-es</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><span style="background-color:rgb(255,255,255)"><font><span style="color:rgb(0,0,153)"><i><b>Saludos.<br><br>Jose Daboin</b></i></span></font></span><br>
</div>