6

I'm trying to run a Powershell script without leaving Eclipse IDE so I setup External tool config as follows:

under "main" tab:

Location: C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe

Working Directory: C:\WINDOWS\system32\windowspowershell\v1.0\

Arguments: "& C:\PowershellScripts\script.ps1"

I save it and click run but nothing happens. A console window stays open diplaying C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe in title. I click on red Stop button but noting seems to happen anyway. The script is not exectued.

What am I missing?

Mrchief
  • 75,126
  • 20
  • 142
  • 189
  • found a workaround: location: C:\WINDOWS\system32\cmd.exe arguments: /c "powershell -file C:\Powershell\Script1.ps1" quotes are important. without them it will not execute the PS script. only thing remaining is to send the 'terminate' command somehow as the console window in eclipse doesn't terminate automatically. – Mrchief Jan 07 '10 at 18:32
  • Oh, it looks like you went the same route as me after some initial hiccups. As for "terminate automatically", I believe that the session would terminate as soon as you hit "enter". – JasonTrue Jan 07 '10 at 18:41

3 Answers3

7

I would probably use the -file argument, as in

-file "C:\PowershellScripts\script.ps1"

you may need to set the execution policy first if it's not already set to unrestricted on your system.

On my machine, a Windows 7 64-bit box with 64-bit Eclipse and a 64-bit jdk (1.6), I am able to get things to work if I set the "arguments" field to:

-executionpolicy unrestricted -file "c:\code\test.ps1"

An alternative that also worked for me was:

Set the application to launch as C:\Windows\System32\cmd.exe Set the arguments field to something like:

/c "powershell -executionpolicy unrestricted -file c:\code\test.ps1"

That does seem excessively Rube Goldbergian to me, but it's worth a try to see if your problems can be worked around by using a normal shell.

I did briefly get symptoms similar to what you describe, but I can't reproduce them anymore.

JasonTrue
  • 19,244
  • 4
  • 34
  • 61
  • btw, you can pass the execution policy as an argument to powershell.exe – x0n Jan 07 '10 at 00:17
  • Yes, as `-executionpolicy unrestricted`, for example. (For some reason that didn't seem to work for me until I had changed the default policy at least once on my machine). – JasonTrue Jan 07 '10 at 00:46
  • My execution policy is unrestricted. "-file"? It's not what the documentation mentions - http://technet.microsoft.com/en-us/library/ee176949.aspx#EBAA Anyway, even that doesn't work. – Mrchief Jan 07 '10 at 15:30
0

Your configuration actually worked for me with the additional -file parameter:

  • Location: C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe
  • Working Directory: C:\WINDOWS\system32\windowspowershell\v1.0\
  • Arguments: -file ${workspace_loc:/my-project/deploy.ps1}

Here I run the script even from within the Eclipse workspace.

Before I had to run a "PowerShell as Administrator" and run:

Set-ExecutionPolicy Unrestricted

That is shown here.

phi
  • 550
  • 8
  • 11
  • Thanks for taking the time but how is this answer any different from the accepted answer? – Mrchief Jun 13 '17 at 19:42
  • 1
    You are right. Its basically the same. I wanted to point out that I manually set the execution policy in before. In addition it is shown how to run a file from within workspace. – phi Jun 19 '17 at 10:14
0

The following argument solved everything for me:

-file "${resource_loc}"
Suraj Kumar
  • 5,547
  • 8
  • 20
  • 42
Kevin
  • 1