Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Output from dos utitilies



  • Please log in to reply
6 replies to this topic
Zvonko
  • Members
  • 173 posts
  • Last active: Jan 24 2016 05:21 PM
  • Joined: 17 Oct 2014

A simple question for all who aren't newbies:

 

A dos utility, used in dos, delivers an output in such a way:

dosutility.exe

> ... An output is displayed ...

 

Which can be redirected, as usually, to a file:

dosutility.exe > output.txt

 

But is there a way to assign this output directly to a variable in AHK?

 

Run, %comspec% /c %A_ScriptDir%\dosutility.exe, %A_ScriptDir%

> ... Assign output to a variable ...

 

 



RHCP
  • Members
  • 1228 posts
  • Last active: Apr 08 2017 06:17 PM
  • Joined: 29 May 2006

There are a few different methods floating around the forums, but this is quite clean:

 

http://www.autohotke...rsion/?p=664674



gilliduck
  • Members
  • 109 posts
  • Last active: Nov 09 2015 01:07 AM
  • Joined: 19 Dec 2013

I personally like to pipe most of mine to the clipboard 

something something | clip

then I can play with it as needed in AHK, either assigning the contents of the clipboard to a variable or if it's just looking for something I leave it in the clipboard.

 

I'm assuming if you can > output.txt then you can probably | clip too.



Zvonko
  • Members
  • 173 posts
  • Last active: Jan 24 2016 05:21 PM
  • Joined: 17 Oct 2014
✓  Best Answer

Thank you very much, RHCP & gilliduck!

 

The objShell method was to complex to me, I first decided to use > output.txt.

 

I tested the '| Clip' method already befor, but found no way to implement it in ahk line.

After your suggestion, gilliduck, I tried again ... and got it work!!!

 

This works in my case:

SetWorkingDir, %A_ScriptDir%

RunWait %comspec% /c program.exe -d %Start% %Length% "%File%" | Clip, %A_ScriptDir%, Hide

;;; -d is a program.exe option, %Start%, %Length%, "%File%" are its start parameters. Hide: the program runs with hidden dos window.


gilliduck
  • Members
  • 109 posts
  • Last active: Nov 09 2015 01:07 AM
  • Joined: 19 Dec 2013

I use the | clip all the time. You just have to be careful to not be doing something else with the clipboard while running your script. I primarily use it in conjunction with InStr() to see if the output of certain commands behaved like I want and go from there.



Zvonko
  • Members
  • 173 posts
  • Last active: Jan 24 2016 05:21 PM
  • Joined: 17 Oct 2014

UPDATE after some months:

 

 


This works in my case:
SetWorkingDir, %A_ScriptDir%

RunWait %comspec% /c program.exe -d %Start% %Length% "%File%" | Clip, %A_ScriptDir%, Hide

;;; -d is a program.exe option, %Start%, %Length%, "%File%" are its start parameters. Hide: the program runs with hidden dos window.

THERE IS A LIMITATION FOR USING THIS CLIP METHOD:

Clip is not available in Win XP (e.g.)!!!

It is a function enabled by Clip.exe, a component of later Windows versions!!!

 

There is a free tool clip.exe available which reproduces the function of the original Windows tool

http://www.c3scripts...msdos/clip.html

http://www.c3scripts.../msdos/clip.zip

but in some cases this is not a solution, because the executable must be located in the Windows directory of users PC ...
 

 

 



space
  • Members
  • 520 posts
  • Last active:
  • Joined: 12 Aug 2014

Zvonko: have you seen the 2nd example (RunWaitOne) on the Run command page ; The following can be used to run a command and retrieve its output that might work with your dos utility? http://ahkscript.org...ommands/Run.htm