如何使用Windows命令获取剪贴板内容?

时间:2013-07-23 19:54:57

标签: windows cmd clipboard copy-paste

例如,我可以将文件复制到剪贴板,如下所示:

clip < file.txt

(现在file.txt的内容在剪贴板中。)

我怎样才能做相反的事情:

???? > file.txt

这样剪贴板的内容将在file.txt

15 个答案:

答案 0 :(得分:20)

您可以使用paste.exe软件来粘贴文本,就像您描述的那样。

http://www.c3scripts.com/tutorials/msdos/paste.html

有了它,你可以这样做:

paste | command

将Windows剪贴板的内容粘贴到指定命令提示符的输入中

paste > filename

将剪贴板内容粘贴到指定文件。

答案 1 :(得分:13)

如果您接受使用{ "id" :123, "subject" : "English", "name": { "firstname": "Hemant", "middlename": "kumar", "lastname": "Mamod" } } (而不是PowerShell),则可以按照需要使用Get-Clipboard

cmd

此方法的出现是您无需安装任何软件。

注意:代替Get-Clipboard > myfile.txt ,您可以使用具有更多选项的Set-Clipboard

注意2::如果您真的想从clip运行它,可以调用cmd,如下面的示例powershell所示。

答案 2 :(得分:5)

澄清来自@Kpym的答案:

powershell -command "Get-Clipboard" > file.txt

这无需使用第三方工具即可直接回答问题。

答案 3 :(得分:2)

第三方剪辑命令可以双向工作。

这是一个:

    CLIP - Copy the specified text file to the clip board
    Copyright (c) 1998,99 by Dave Navarro, Jr. (dave@basicguru.com)

答案 4 :(得分:2)

我在此页面上有一对实用程序(来自Clip命令之前是Windows的一部分):

http://www.clipboardextender.com/general-clipboard-use/command-window-output-to-clipboard-in-vista

其中有两个实用程序,Clip2DOS和DOS2Clip。你想要Clip2DOS:

Clip2DOS版权所有2006 Thornsoft Development 将剪贴板文本(1024字节)转储到标准输出。
用法:Clip2Dos.exe&gt; out.txt 结果:文本在文件中。 限制:1024字节。 许可证:免费,免费啤酒! http://www.thornsoft.com/dist/techsupport/dos2clip.zip

DELPHI SOURCE包括!

嘿,这是(Clip2DOS.dpr):

{Clip2DOS - copyright 2005 Thornsoft Development, Inc.  All rights reserved.}
program Clip2Dos;

{$APPTYPE CONSOLE}

uses
  Clipbrd,
  ExceptionLog,
  SysUtils;

var
   p : Array[0..1024] of Char;
begin
  try
    WriteLn('Clip2DOS Copyright 2006 Thornsoft Development');
    Clipboard.GetTextBuf(p,1024);
    WriteLn(p);
  except
    //Handle error condition
    on E: Exception do
            begin
              beep;
              Writeln(SysUtils.format('Clip2DOS - Error: %s',[E.Message]));
              ExitCode := 1;    //Set ExitCode <> 0 to flag error condition (by convention)
            end;
  end
end.

答案 5 :(得分:2)

获取剪贴板的内容

从win cmd:

powershell get-clipboard

或(通过HTML解析器中的临时文件)在cmd上:

echo x = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text") > temp.vbs
echo WScript.Echo x >> temp.vbs
cscript //nologo temp.vbs

输出可能会重定向到文件。

答案 6 :(得分:1)

使用doskey宏定义功能,您可以执行以下操作:

public LocalDateTime setDate(long ldate){

  LocalDateTime newDate;

  //{convert from long to LocalDateTime}

  return newDate
}

然后(例如)

doskey unclip=(powershell -command "Get-Clipboard") $*

答案 7 :(得分:0)

以下是Dave Navarro的CLIP计划,正如@foxidrive的回答所述。这篇文章中提到了copying-from-clipboard-to-xywrite

此页面上提供了下载链接以及许多其他资源:http://www.lexitec.fi/xywrite/utility.html

以下是下载的直接链接: &#34; DOWNLOAD Clip.exe Dave Navarro,Jr。&#34;

从剪贴板复制到剪贴板

答案 8 :(得分:0)

粘贴板是另一种选择。它也可以从WSL运行。首先,通过choco安装:

choco install pasteboard

然后命令很简单

pbpaste.exe > file.txt

这在cmd和wsl bash中有效。

答案 9 :(得分:0)

vbs 可能是可能的:

Option Explicit
 
' Gets clipboard's contents as pure text and saves it or open it

Dim filePath : filePath = "clipboard.txt"

' Use the HTML parser to have access to the clipboard and get text content
Dim text : text = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text")

' to open
If Not IsNull(text) then
Dim WshShell, somestring, txFldr2Open
Set WshShell = WScript.CreateObject("WScript.Shell")

txFldr2Open = "C:\Users"
txFldr2Open = text

somestring = "EXPLORER.exe /e," & txFldr2Open ', /select
WshShell.run somestring
Set WshShell = Nothing
else 
msgbox("Empty")

end if



' Create the file and write on it
msgbox(text)
Dim fileObj : Set fileObj = CreateObject("Scripting.FileSystemObject").CreateTextFile(filePath)
fileObj.Write(text)
fileObj.Close

答案 10 :(得分:0)

您可以使用 cbecho,这是我用纯 C 编写的程序。它将任何剪贴板文本发送到标准输出,您可以从那里将其通过管道传输到其他程序。

答案 11 :(得分:0)

嗯,从一百万年前开始,我们做了这样的事情:

type con > filename.txt

... 然后在等待提示中执行粘贴操作(Ctrl-v,单击鼠标中键,或从菜单中选择“编辑”->“粘贴”)。这将捕获 stdin 缓冲区(控制台设备,名为“con”),并且当接收到文件结尾时,它将内容写入文件。因此,在粘贴之后,您键入“Ctrl-z”以生成一个 EOF,并且 type 命令终止,并且您的粘贴缓冲区(剪贴板)的内容被捕获在“filename.txt”中。

答案 12 :(得分:-2)

我知道我真的来晚了,但是你可以这样写:

type file.txt | clip

所以剪贴板的内容将是file.txt的内容

答案 13 :(得分:-3)

我不确定当时是否不支持该命令,但确实可以使用

clip > file.txt

答案 14 :(得分:-7)

这个肮脏的技巧适合我的需求,它附带Windows!

notepad.exe file.txt

Ctrl + V Ctrl + S Alt + F X