Use Clipboard instead of temp-file from CMD-prompt - Possible? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Albireo
Posts: 1774
Joined: 16 Oct 2013, 13:53

Use Clipboard instead of temp-file from CMD-prompt - Possible?

05 Oct 2020, 09:34

Hi!
Sending a result from a CMD prompt (eg dir) to a temporary file (c:\temp\out.txt) is not difficult. (something like this)

Code: Select all

outFile := "c:\temp\out.txt"
If FileExist(outFile)
	FileDelete %OutFile%
 
RunWait % ComSpec " /c dir c:\temp\*.* > " outFile,, Hide

FileRead DirTree, %outFile%
FileRecycle %outFile%
MsgBox ,, %A_ScriptName% - Row %A_LineNumber%, Ready! `n`n%DirTree%
The only problem I see with this is that the file does not have the correct Code Page - for me.
17 File(s) 729ÿ775ÿ009 bytes (ÿ instead of "space")
But is it possible (in some way) to send the result directly to an variable och Clipboard from the CMD-window?
Something like this .: (don't work)

Code: Select all

Clipboard := ""
RunWait % ComSpec " /c dir c:\temp\*.* > " Clipboard,, Hide
MsgBox % ClipBoard
(maybe better to save Clipboard before CMD/dir and restore after CMD/dir?)
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Use Clipboard instead of temp-file from CMD-prompt - Possible?  Topic is solved

05 Oct 2020, 11:03

Try:

Code: Select all

RunWait % ComSpec " /c dir |Clip", C:\Temp, Hide
MrDoge
Posts: 161
Joined: 27 Apr 2020, 21:29

Re: Use Clipboard instead of temp-file from CMD-prompt - Possible?

05 Oct 2020, 11:33

I forgot where I found this (in the forums, not mine)

Code: Select all

output:=ComObjCreate("WScript.Shell").Exec("Dir").StdOut.ReadAll()
clipboard:=output
msgbox % output
Albireo
Posts: 1774
Joined: 16 Oct 2013, 13:53

Re: Use Clipboard instead of temp-file from CMD-prompt - Possible?

05 Oct 2020, 13:09

Thanks for the suggestions!
MrDoge wrote:
05 Oct 2020, 11:33
...

Code: Select all

output:=ComObjCreate("WScript.Shell").Exec("Dir").StdOut.ReadAll()
clipboard:=output
msgbox % output
An old solution from Lexikos, among others (but I got an error message)
Error: 0x80070002 - The file can not be found.
Source: WshShell.Exec


Xtra wrote:
05 Oct 2020, 11:03

Code: Select all

RunWait % ComSpec " /c dir |Clip", C:\Temp, Hide
This solution seems to work.
But I can not find any information about Clip (is it a type of variable?)

Since it is not the Dir instruction but certutil.exe that I would handle, the program will be different.
This is an example of my solution .:

Code: Select all

FileSelectFile SelectedFile, 3, c:\Temp, Open a file, Text Documents (*.jpg)
If !FileExist(SelectedFile)
{	MsgBox 16, %A_ScriptName% - Row %A_LineNumber%, You didn't select anything.
	ExitApp
}

md5value := md5(SelectedFile)

MsgBox ,, %A_ScriptName% - Row %A_LineNumber%, % "MD 5`n`n- " md5value "`n`n- " SelectedFile
ExitApp

md5(file)
{	If !FileExist(file)
		Return

	RunWait % ComSpec " /c " A_WinDir "\System32\certutil.exe -hashfile """ file """ MD5 | Clip" ,, Hide	
	Loop Parse, Clipboard, `n, `r
	{	If ( A_Index = 2 )
		{	line := A_LoopField
			Break
		}
	}
	Return line
}
RickC
Posts: 302
Joined: 27 Oct 2013, 08:32

Re: Use Clipboard instead of temp-file from CMD-prompt - Possible?

05 Oct 2020, 20:12

Clip refers to C:\Windows\System32\clip.exe. As the filepath is already referenced by the PATH environment variable you only need to use the command clip itself to refer to the command and its filepath.

Hope this helps...
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Use Clipboard instead of temp-file from CMD-prompt - Possible?

09 Oct 2020, 12:37

Albireo wrote:
05 Oct 2020, 13:09
Thanks for the suggestions!
MrDoge wrote:
05 Oct 2020, 11:33
...

Code: Select all

output:=ComObjCreate("WScript.Shell").Exec("Dir").StdOut.ReadAll()
(...) (but I got an error message)
Error: 0x80070002 - The file can not be found.
Source: WshShell.Exec

For reference:

Code: Select all

; https://www.vbsedit.com/html/f3358e96-3d5a-46c2-b43b-3107e586736e.asp
WshRunning := 0 ; WshFinished := 1
WshShell  := ComObjCreate("WScript.Shell")
oExec := WshShell.Exec("cmd /c DIR """ . A_Desktop . """")
#Persistent
SetTimer, wait, -1
return

wait:
	if (oExec.Status = WshRunning)
		SetTimer,, -10
	else {
		clipboard := oExec.StdOut.ReadAll()
	ExitApp
	}
return
A_AhkUser
my scripts
Albireo
Posts: 1774
Joined: 16 Oct 2013, 13:53

Re: Use Clipboard instead of temp-file from CMD-prompt - Possible?

09 Oct 2020, 14:34

Thank you! @A_AhkUser
(sorry I do not understand)
What is supposed to happen?
How is this used?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], niCode, peter_ahk and 166 guests