繁体   English   中英

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

[英]How can I call programs that are already running to open new files from Perl or a bash script?

我正在使用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 &";
}

谢谢大家!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM