Author Topic: Capturing windows command output  (Read 3383 times)

6bit

  • Guest
Capturing windows command output
« on: June 24, 2018, 03:42:46 PM »
I have a voice command that executes a windows console application.
The application writes something to the terminal window but the window exits immediately and I can't see the result.
I was able to send the result to a text variable and then send the variable contents to the clipboard - and then copy the clipboard to an editor screen.
Is there an easier way of capturing the output?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Capturing windows command output
« Reply #1 on: June 24, 2018, 05:03:03 PM »
Can you be more specific? Capturing the output is done by VoiceAttack itself, so there's little improvement to be made there.

Are you trying to display the output somewhere so you can read it, or does it need to be passed to another application for further processing?


In case of the former, you could output the contents of STDOUT to VoiceAttack's log using an inline C# function:
Code: [Select]
using System;

public class VAInline
{
public void main()
{
string[] STDOUT = VA.GetText("~STDOUT").Split(new[] {Environment.NewLine}, StringSplitOptions.None);
Array.Reverse(STDOUT);
foreach( string i in STDOUT)
{
VA.WriteToLog(i,"");
}
}
}

Note that it's looking for a variable named "~STDOUT"; The "~" prefix means the variable value will be discarded(it'll return "Not Set") after the command is finished executing.

If you have the VoiceAttack log set to "New entries at bottom", you'll want to remove the "Array.Reverse(STDOUT);" line.


If you anticipate the application not printing anything to the console, you'll want to add a check for that:
Code: [Select]
using System;

public class VAInline
{
public void main()
{
string STDOUT = VA.GetText("~STDOUT");
if (String.IsNullOrWhiteSpace(STDOUT))
{
VA.WriteToLog("STDOUT is blank","red");
return;
}
string[] STDOUTlines = STDOUT.Split(new[] {Environment.NewLine}, StringSplitOptions.None);
Array.Reverse(STDOUTlines);
foreach( string line in STDOUTlines)
{
VA.WriteToLog(line,"");
}
}
}



If you don't mind using external files, you could just create a batch file that runs your application, followed by a pause instruction so the console window stays open.

E.G.
Code: [Select]
start "" "C:\MyApplication"
pause
« Last Edit: April 22, 2019, 06:25:04 PM by Pfeil »

6bit

  • Guest
Re: Capturing windows command output
« Reply #2 on: June 24, 2018, 10:02:59 PM »
Thanks for the clue. A wrapper bat file with a timeout worked just fine.
The command is curl or a homegrown equivalent. I need to see the output
while debugging an HTTP connection but won't care later, so the wrapper
is fine.

While you might be reading..
I wanted to use curl which is in Windows\System32\curl.exe but while it can be used from
the command line and can be found with File Explorer, it is invisible to VA's … dialog in
'Run an Application'. So I rolled my own. Can't seem to access it except with a full path C:\…,
would like to just use the name to save typing.

Thanks again.


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Capturing windows command output
« Reply #3 on: June 24, 2018, 10:30:12 PM »
VoiceAttack is a 32-bit application, so C:\Windows\System32 actually redirects to C:\Windows\SysWOW64 instead, even though the path still appears the same(this is to maintain compatibility with older applications, but frankly Windows-on-Windows is an nontransparent mess, in my opinion).

Put your executable in C:\Windows\SysWOW64, and it should work.

6bit

  • Guest
Re: Capturing windows command output
« Reply #4 on: June 26, 2018, 09:51:56 AM »
Wow