2010-02-25 21:35:38 +0000 2010-02-25 21:35:38 +0000
83
83
Advertisement

如何将文件的内容载入剪贴板?

Advertisement

我有一个文件,我需要将其内容复制到另一个文件或应用程序中,而不是打开它,选择所有的文本,然后复制和粘贴,我想知道我是否可以有效地cat文件内容到剪贴板。这是否可行?

一个Windows程序就可以了,但在Linux上工作的东西也会很有用。我不使用Mac,但它可能对其他人有用。如果能在命令行上完成,那就加分。

Advertisement
Advertisement

答案 (6)

63
63
63
2010-02-25 21:51:07 +0000

既然你没有问Mac的情况。cat file | pbcopy(同样pbpaste)。

51
51
51
2010-02-25 22:35:24 +0000

xclip (可能在你的Linux系统的仓库里有)将适用于任何X11系统,包括大多数Linux版本,甚至X在windows或Mac OSX下运行。

使用示例。xclip -sel clip < ~/.ssh/id_rsa.pub

35
Advertisement
35
35
2010-02-25 22:33:36 +0000
Advertisement

在Linux中,你可以用xsel来模仿pbcopypbpaste

alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'

资料来源: Where’s Walden?“ pbcopy and pbpaste for Linux

13
13
13
2012-11-05 06:17:33 +0000

在Linux和其他可能支持xclip的系统上。

xclip -i -selection c file_to_copy_to_clipboard.txt

我看到@JustinSmith也提到了xclip,但缺少一个例子,所以只好自己去查。

另一个有用的方法:将剪贴板粘贴到文件中。

xclip -o -selection c > file_to_paste_to.txt

Source

2
Advertisement
2
2
2017-06-06 10:44:32 +0000
Advertisement

使用命令 “type "相当于windows中的 "cat",将文件内容以文本格式传送到stdout(标准输出),因为你使用的是终端/提示模拟器(windows中的CMD)。所以你可以把这些命令组合成这样:

type myFile.txt > clip

现在myFile.txt的内容被传输到clipBoard缓冲区(我认为它只是一个缓冲区,因为它不是linux)。这也是一个全局值,所以在整个操作系统中一次只保留一个值。所以这是 "复制 "功能,现在是 "粘贴":

-要么你想把CLIP的值追加到一个现有的文件,就像通常的东西:

-要么,你想添加/创建一个新的文件,与CLIP的值一样。

1
1
1
2013-08-11 20:45:05 +0000

使用这个程序f2clip。从命令行运行它。它将文件内容复制到剪贴板。我用它将文本文件复制到浏览器中,以便进一步处理。从 http://smrz.xf.cz/f2clip.exe 或者从这个源头写你自己的程序(很丑):

program f2clip;

 {$APPTYPE CONSOLE}

 uses
SysUtils,
clipbrd;

var i,r:integer;
    s:string;
 f:file;
 buf:array[0..1024*1024-1] of byte;

 data:string;
 d:pointer;
 begin
 try

 { TODO -oUser -cConsole Main : Insert code here }
    if (paramcount=0) then begin
    writeln('parameters: f2clip filename.txt');
end else begin
    write('parameter count: ');
  writeln(paramcount);  
    for i:=1 to paramcount do begin
    s:=paramstr(i);
    writeln('file: ',s);

    assignfile(f,s);
    reset(f,1);
    BlockRead(f,buf,1024*1024,r);
    writeln('size: ',r);
    buf[r]:=0;

    d:=@(buf[0]);
    data:=PAnsiChar(d);
Clipboard.AsText := data;
    close(f);
  end;

  end;

 except
   on E:Exception do
     Writeln(E.Classname, ': ', E.Message);
 end;
end.

对不起。

Advertisement

相关问题

7
7
3
13
5
Advertisement