Copying to clipboard from .txt file via .bat file
13,365
Solution 1
@bgalea's answer is correct, you should use clip in your command.
However, please note that you should put double quotes around the filename, as your script will otherwise break if the filename contains spaces.
Also not that you can also use input <
in your code, which instead of piping output from another command, immediately puts the contents into a command. To conclude, the following codes will both work:
@echo off
clip < "c:\Users\Test user\Desktop\paste scripts\ProgramTemplate\ProgramTemplate.txt"
or
@echo off
type "c:\Users\Test user\Desktop\paste scripts\ProgramTemplate\ProgramTemplate.txt" | clip
Solution 2
type file.txt | clip
See type /?
and clip /?
for help.
See Novice Batch Issue- Creating Files for a list of command prompt punctuation.
Author by
Evan
Updated on June 13, 2022Comments
-
Evan almost 2 years
I was following this guide but I cannot get it to function properly. It's supposed to copy the text contained in ProgramTemplate.txt to the clipboard when you run the .bat file. Below is the .bat file code:
C:\\Windows\System32\cmd.exe /k < c:\Users\Test user\Desktop\paste scripts\ProgramTemplate\ProgramTemplate.txt c:\exit
-
Squashman over 8 yearsYou are missing the
CLIP
command in your code. It shows it plain as day in the website you linked to. -
Evan over 8 yearsI have clip in the file, forgot to type it into this question.
-
-
Dennis van Gils over 8 yearsYou should put double-quotes around the filename, as I explain in my answer.