在 Powershell_ISE (Windows Server) 中執行和編輯 Perl/Python/非 Powershell - 腳本

在 Powershell_ISE (Windows Server) 中執行和編輯 Perl/Python/非 Powershell - 腳本

我在帶有 Powershell_ISE 的 Windows Server (2012) 上,在安裝其他軟體之前,我想在 Powershell_ISE 中編輯和測試腳本(這是一個更好的本國的比使用記事本 + cmd.exe 更好的解決方案,因為例如選項卡式編輯)

想法:選單項目的鍵盤快速鍵(在選單中的「附加元件」下),其中執行程式使用目前腳本路徑作為參數進行呼叫。

我嘗試了以下幾行:

$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Perl",{$cur=$psISE.CurrentFile; saps "c:\strawberry\perl\bin\perl.exe" $cur.FullPath },'Ctrl+Alt+q')

(使用 saps=start-process)或

$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Perl",{$cur=$psISE.CurrentFile; & "c:\strawberry\perl\bin\perl.exe" $cur.FullPath },'Ctrl+Alt+e')

(使用 & = 執行外部命令)或

$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Perl",{$cur=$psISE.CurrentFile; saps "c:\strawberry\perl\bin\perl.exe" $cur.FullPath -wait },'Ctrl+Alt+w')

(啟動進程並等待)

cmd 視窗短暫閃爍,但在控制台窗格中沒有輸出。 (Perlscript 只是列印“test”,並且在通過& "c:\strawberry\perl\bin\perl.exe" $cur.FullPath在控制台窗格中運行:直接執行時可以正常工作)

如果這可行,您可以將此行新增至 Powersehll_ISE 的 $profile 中,以透過呼叫適當的二進位檔案來編輯/執行所有語言的腳本

答案1

一分鐘後,我嘗試了以下行(與&結合使用,-wait它有效:

$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Perl-Menu_Entry",{$cur=$psISE.CurrentFile; & "c:\strawberry\perl\bin\perl.exe" $cur.FullPath -wait },'Ctrl+Alt+y') 

(您也可以使用“F”鍵 - 例如:不用“ctrl+alt+y”,只需使用“F4”)

若要在執行之前儲存文件,請新增$psise.CurrentFile.Save()至該行:

$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Perl-Menu_Entry",{$psise.CurrentFile.Save(); $cur=$psISE.CurrentFile; & "c:\strawberry\perl\bin\perl.exe" $cur.FullPath -wait },'Ctrl+Alt+y') 

相關內容