hi SKAN
why do you avoid the PeekNamedPipe call that many of the newer iterations of StdOutToVar have used?
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=791
RunCMD() v0.97 : Capture stdout to variable. Non-blocking version. Pre-process/omit individual lines.
Re: RunCMD()
@garry, this works for wget.
Thanks again, @SKAN!
Code: Select all
#SingleInstance, Force
#Include RunCmd.ahk
;varout := StdOutStream("cmd.exe /c %comspec% /c C:\msys64\usr\bin\wget.exe https://wordpress.org/latest.zip") ; prior attempt using stdout2var.ahk
varout := RunCmd("C:\msys64\usr\bin\wget.exe https://wordpress.org/latest.zip")
msgbox %varout%
Re: RunCMD()
No, I'm not avoiding.
1) Sean would've used it had he found it to be better. (He was thorough with API functions)
2) I'm yet to find a CLI utility that hangs.. I need a problem to compare and find if PeekNamedPipe() is better.
Re: RunCMD()
@burque505
@SKAN
thank you very much , works fine ( example with wget.exe )
@SKAN
thank you very much , works fine ( example with wget.exe )
Code: Select all
;- https://www.autohotkey.com/boards/viewtopic.php?f=6&t=74647&start=60
;- example downloads a mp3-file to folder C:\users\%a_username%\Downloads ( normal downloadfolder )
;---------------------
#SingleInstance, Force
#Include RunCmd.ahk
;---------------------
f1:="http://74.136.132.35/MUSIC/RHAPSODY/J/Johnny%20Horton/American%20Originals/02%20-%20North%20To%20Alaska.mp3"
SplitPath,f1, name, dir, ext, name_no_ext, drive
name:= URLdecode(name) ;- remove %20 etc in filename
wget1:="D:\M_GARRY\PROGRAMME_SA\WGET\wget.exe" ;- <<< here is wget.exe
loop,%wget1% ;- create shortpath
SP1:=A_loopFileShortPath
folderx2:="C:\Users\" . a_username . "\Downloads" ;- <<< Download_folder
ifnotexist,%folderx2%
filecreatedir,%folderx2%
f2 := folderx2 . "\" . name ;- File-fullpath
transform,s,chr,34
;--------------
VAR:=sp1 . " --output-document=" . s . f2 . s . " " . f1 ;- wget downloads file to defined folder
varout:=Runcmd(var)
msgbox %varout% ;- see variable ( wget-finished )
;run,%folderx2% ;- open folder
;run,%f2% ;- run file
return
;--------------
URLdecode(str) {
Loop
If RegExMatch(str, "i)(?<=%)[\da-f]{1,2}", hex)
StringReplace, str, str, `%%hex%, % Chr("0x" . hex), All
Else Break
Return, str
}
return
;============================================================
Re: RunCMD()
@garry, your code works great.
Regards,
burque505
Regards,
burque505
Re: RunCMD()
Thank you! That solves my problem, but not perfectly. Still a little problem about encoding. Anyway, thanks for your script.burque505 wrote: I've been trying to figure out where I found this code, cli_stdio.ahk.
Re: RunCMD()
@xml123, I'm glad it was at least of some help.
Have you tried (pick the correct code page) or for the encoding problem?
Regards,
burque505
Have you tried (pick the correct code page)
Code: Select all
cli_stdout("","65001")
Code: Select all
cli_stdin("","65001")
Regards,
burque505
Re: RunCMD()
@burque505
It work! Now the scripts works perfectly. Thanks for your generous help.
It work! Now the scripts works perfectly. Thanks for your generous help.
Re: RunCMD()
@xml123, I'm glad it worked for you. If you are able to share any of your code, I'm sure I could learn from it. I've never coded anything using cli_stdio.ahk myself, I just found it lurking in my file system.
Regards,
burque505
Regards,
burque505
Re: RunCMD()
@burque505
Just a simple piece of code. Of course I can show it if you don't mind this.
I'm using sublimetext as my text editor. There is a cli version "subl.exe", which can be used like this: "subl [arguments] - Edit stdin". I want to create a shortcut that copy what I'm selecting directly into sublimetext instead of open the editor then copy and paste. Here is my code.
Just a simple piece of code. Of course I can show it if you don't mind this.
I'm using sublimetext as my text editor. There is a cli version "subl.exe", which can be used like this: "subl [arguments] - Edit stdin". I want to create a shortcut that copy what I'm selecting directly into sublimetext instead of open the editor then copy and paste. Here is my code.
Code: Select all
#include lib/cli_stdio.ahk
!s::
Send, ^c
ClipWait
cli_createprocess("C:\Program Files\SublimeText\subl.exe -")
cli_stdin(Clipboard,"UTF-8")
cli_close()
return
Re: RunCMD()
@xml123, thanks, I'll try it. I have Sublime Text available, I think.
EDIT: Thanks, works great! For my system I used this. I had to add a sleep command to wait for the program to load before pasting.
Regards,
burque505
EDIT: Thanks, works great! For my system I used this. I had to add a sleep command to wait for the program to load before pasting.
Code: Select all
#include cli_stdio.ahk
!u::
Send, ^c
ClipWait
cli_createprocess("C:\Program Files\Sublime Text 3\subl.exe mytext.txt")
cli_stdin(Clipboard,"UTF-8")
sleep 2000
Send, ^v
cli_close()
return
burque505
Last edited by burque505 on 23 Jun 2020, 07:40, edited 1 time in total.
Re: RunCMD()
@burque505
Maybe you misunderstood me. The parameter - is necessary. In your situation the command should be C:\Program Files\Sublime Text 3\subl.exe mytext.exe -. In this case, you needn't sleep or send ctrl+v.
Append:
You are right. The versions of sublime text we use are different. I'm using the beta version 4074. Here is my help.
It seems that build 3211 doesn't support editing stdin. Therefore the command cli_stdin(Clipboard,"UTF-8") is useless.
Cause it is really off-topic, I shouldn't add more posts about sublime.
Maybe you misunderstood me. The parameter - is necessary. In your situation the command should be C:\Program Files\Sublime Text 3\subl.exe mytext.exe -. In this case, you needn't sleep or send ctrl+v.
Append:
You are right. The versions of sublime text we use are different. I'm using the beta version 4074. Here is my help.
Code: Select all
Sublime Text build 4074
Usage: subl [arguments] [files] Edit the given files
or: subl [arguments] [directories] Open the given directories
or: subl [arguments] -- [files] Edit files that may start with '-'
or: subl [arguments] - Edit stdin
...
Cause it is really off-topic, I shouldn't add more posts about sublime.
Last edited by xml123 on 23 Jun 2020, 10:16, edited 2 times in total.
Re: RunCMD()
@xml123, thanks, I did misunderstand (I also edited my post above to reflect 'mytext.txt', not 'mytext.exe', which was a typo).
However, I just tried it, and it doesn't work with my installation. Rather, it opens two text files ('mytext.txt' and '-') and, without a sleep command and ctrl+v it pastes nothing.
Perhaps the command line options in our respective versions are different?
Here's what they are in mine:
PS: This is getting pretty far off-topic from the OP.
Regards,
burque505
However, I just tried it, and it doesn't work with my installation. Rather, it opens two text files ('mytext.txt' and '-') and, without a sleep command and ctrl+v it pastes nothing.
Perhaps the command line options in our respective versions are different?
Here's what they are in mine:
Code: Select all
Sublime Text build 3211
Usage: subl [arguments] [files] Edit the given files
or: subl [arguments] [directories] Open the given directories
Arguments:
--project <project>: Load the given project
--command <command>: Run the given command
-n or --new-window: Open a new window
-a or --add: Add folders to the current window
-w or --wait: Wait for the files to be closed before returning
-b or --background: Don't activate the application
-s or --stay: Keep the application activated after closing the file
-h or --help: Show help (this message) and exit
-v or --version: Show version and exit
Filenames may be given a :line or :line:column suffix to open at a specific
location.
Regards,
burque505
Re: RunCMD()
Thank you.Sam_ wrote:This function is awesome! Thank you for sharing it.
Quickly written.. not well tested. I will try to post a proper demo later. (streaming to an edit control)Sam_ wrote:Will you pretty please also provide a streaming version?
Obsolete version
RunCMD() v0.93
Code updated:
New non-blocking version with streaming support. Check out the demo in title post.
New non-blocking version with streaming support. Check out the demo in title post.
Re: RunCMD() v0.93 : Capture stdout to variable. Non-blocking version. Pre-process/omit individual lines.
Nice, @SKAN, thank you!!
Regards,
burque505
Regards,
burque505
Re: RunCMD() v0.93 : Capture stdout to variable. Non-blocking version. Pre-process/omit individual lines.
I had used a few methods to run cmds and retrieve their output, your seems the most complete and versatile, also the real time stream ret seems something I will be using for a few projects.
Thank you for your hard work @SKAN it really is well appreciated!
Thank you for your hard work @SKAN it really is well appreciated!
Re: RunCMD() v0.93 : Capture stdout to variable. Non-blocking version. Pre-process/omit individual lines.
Do let me know if documentation needs to be better.
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: No registered users and 170 guests