我正在使用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打开文件,而不必在每个应用程序中单独打开文件。有什么想法吗?
发布于 2019-04-27 02:27:14
这个解决方案是@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 &";
}感谢你们所有人!
https://stackoverflow.com/questions/55714531
复制相似问题