gpt4 book ai didi

linux - 如何调用已经运行的程序从 Perl 或 bash 脚本打开新文件?

转载 作者:太空宇宙 更新时间:2023-11-04 11:52:17 29 4
gpt4 key购买 nike

我正在使用 Perl 脚本查找处理来自另一个进程的错误所需的数据。在 OSX 中,Perl 脚本中的这些行在我的浏览器和文本编辑器中打开所需的站点和文件。下面是适用于 OSX 的代码:

 if ($^O eq "darwin") {
system `open -a /Applications/Firefox.app https://site`;
system `open -a /Apopen -a /Applications/Komodo.appplications/Komodo.app file1.md file2.md`;
system `open -a /Applications/Komodo.app file3.md`;}

我可以重复运行此脚本,应用程序将添加带有新打开文件的选项卡。

但是,我需要在 Linux 上运行相同的工具,但我还没有找到任何方法。以下是我尝试使其适应 Linux 的方法。

 if ($^O eq "linux") {
system `firefox local_file.html & disown`;
system `firefox https://site1 https://sitex & disown`;
system `komodo file1 file2 filex & disown`;
}

我已经调整了 Perl 脚本,以便它输出一个我可以从命令行运行的 shell(根据@Grant McLean 的建议,最新版本):

xdg-open https://www.site1 & disown
xdg-open https://www.site2 & disown
xdg-open /home/.../file1.html & disown
xdg-open /home/.../file2.md & disown
xdg-open /home/.../file3.md & disown

我从@Grant McLean 的建议中了解到,如果我将它集成到 Perl 脚本中,这些行将是,例如,

system "xdg-open { file | site } & disown";

但由于 shell 会挂起系统,我假设从 Perl 脚本向系统传递命令也会挂起系统。

我希望能够让浏览器和文本编辑器从 shell 打开文件,而不必在每个应用程序中单独打开文件。有什么想法吗?

最佳答案

解决方案是@grantmclean 建议的变体。当我尝试他的解决方案时,它不起作用,因为我试图一次 xdg-open 多个文件或站点。一次打开一个有效:

if ($^O eq "linux") {
system "xdg-open https://site1 &";
system "xdg-open https://site2 &";
my @tWs = split / /,$tW_files;
foreach (@tWs) {
system "xdg-open $_ &" # opens a series of local files
}
system "xdg-open file_y &";
system "xdg-open file_z &";
}

谢谢大家!

关于linux - 如何调用已经运行的程序从 Perl 或 bash 脚本打开新文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55714531/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com