簡體   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