0

I am on a Windows Server (2012) with Powershell_ISE and befor installing additional software I wanted to edit and test a script in the Powershell_ISE (it's a better native solution than using notepad + cmd.exe because of tabbed editing for example)

Idea: Keyboard Shortcut to a menu-entry (under "Add-Ons" in the menu) where the perl.exe is called with the current script-path as parameter.

I tried the following lines:

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

(with saps=start-process) or

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

(with & = execute external command) or

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

(start-process and wait)

A cmd-Window is shortly flashing but in the console-pane there is no output. (the Perlscript just prints "test" and is working when executed directly by running: & "c:\strawberry\perl\bin\perl.exe" $cur.FullPath in the console-pane)

If this would work, you could add this line to the $profile of the Powersehll_ISE to edit/execute scripts of all languages by calling the appropriate binary

0

One minute later I tried the following line (with & in combination with -wait and it works:

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

(you can use the "F"-Keys, too - e.g.: instead of 'ctrl+alt+y' just use 'F4')

To save the file before executing add $psise.CurrentFile.Save() to the line:

$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') 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.