windows - How can I pipe console output directly to Notepad?
2014-06
I'm running an application on the command prompt or a Git shell, and I would like to get the output into Notepad, for easier review and editing later on.
I tried the following, but I always get an empty instance of Notepad:
diff file1.txt file2.txt | notepad
I'm aware that I can redirect the output to another file and then open the file in Notepad. I'd like to avoid the extra step, because I'm just used to piping into Vim or less on non-Windows systems.
From what I can tell, there is no way to directly pipe into Notepad.
However, you can pipe into clip
and then paste in notepad, like so:
diff file1.txt file2.txt | clip && notepad
Then just press Ctrl+V in Notepad.
Consider using Vim, or in your case gVim if you prefer a graphical environment.
You can then pipe into it with a single hyphen as an argument, which instructs Vim/gVim to read from standard input.
diff file1.txt file2.txt | gvim -
Something like this "might" work.
Aw, ya didn't realize this is something you'd be doing manually each time (from the sounds of it). You might be able to make some sort of macro or something to do it for you each time to speed up the process. Not sure on that one.
diff file1.txt file2.txt > file.txt | sleep 1 | notepad.exe file.txt | rm file.txt
It would have to finish writing the diff contents to file.txt in order for it to load the entirety of the diff operation which I'm not sure if it'll do. There might be a way to pause somehow between the pipe operation if that is the case.
This is totally possible; I just tried it. I'm assuming Notepad is set to open txt files by default:
diff file1.txt file2.txt > output.txt && start output.txt && timeout /T 3 && del output.txt
OK, you're technically creating a file, but it doesn't get saved.
Piping into more is also an option.
How about using AutoHotkey?
Save the following as stdin.ahk
and put it in your AutoHotkey directory:
StdIn(max_chars=0xfff)
{
static hStdIn=-1
; The following is for vanilla compatibility
ptrtype := (A_PtrSize = 8) ? "ptr" : "uint"
if (hStdIn = -1)
{
hStdIn := DllCall("GetStdHandle", "UInt", -10, ptrtype) ; -10=STD_INPUT_HANDLE
if ErrorLevel
return 0
}
max_chars := VarSetCapacity(text, max_chars*(!!A_IsUnicode+1), 0)
ret := DllCall("ReadFile"
, ptrtype, hStdIn ; hFile
, "Str", text ; lpBuffer
, "UInt", max_chars*(!!A_IsUnicode+1) ; nNumberOfBytesToRead
, "UInt*", bytesRead ; lpNumberOfBytesRead
, ptrtype, 0) ; lpOverlapped
return text
}
loop
{
sleep 100 ;wait for data
Buffer:=StdIn()
PipeText:=PipeText . Buffer
IfWinActive Untitled - Notepad
{
SendInput {Raw}%PipeText%
PipeText =
}
}
Then the command line:
ping -t www.google.com | AutoHotkeyA32.exe stdin.ahk
Pipes the output of the command into Notepad, so long as the window is open and titled Untitled - Notepad
. In the event that the window is not active then it will cheerfully buffer in the background until the window is active. You can even go away to another program and it will carry on buffering once more.
This seems to die when the program outputting to our standard input dies though...
(For information, the stdin() code was shamelessly half-inched from here)
Just because I don't see it mentioned, Baretail is awesome for this, and has a free version.
Better yet... install Cygwin and workaround all this "lack of features" of Windows. You can then use the command you already know.
AFAIK, very few Windows program support pipelining, even worse for GUI programs.
You can try to open feature requests to one of the "windows tail" programs to add that.
Hi Everyone I am trying to find out if there is a fast way to delete several (>10) Notepad files at the same time without going through the open file, delete file routine for each Notepad file? I am running Vista Home Premium Thank you.
Open the folder that contains your "several Notepad files" (.txt I suppose), hold down the CTRL key and highlight each file you want to delete with a single left click. When done, hit DEL (or Shift + DEL to bypass the Recycle Bin).
What about selecting all the text files in the directory and using Shift + Delete keys
Depends on the structure of the folder, but you could show DETAILS view, sort by (file) TYPE. Now all the .txt files are together and you can click the first, then SHIFT + click the last. All .txt files are now selected and just hit delete.