0

I run this command script:

$hm = "$Env:USERPROFILE" $eclipse_path = "$hm\eclipse\committers-2019-09\eclipse\eclipse.exe" $sp = { "$eclipse_path -data C:\SharedData\Projects\Tutorial &" Write-Host "Eclipse starting" } Invoke-Command -ScriptBlock $sp

with the following results:

>>> bin/dev.ps1 C:\Users\jgoss\eclipse\committers-2019-09\eclipse\eclipse.exe -data C:\SharedData\Projects\Tutorial & Eclipse starting >>>

It appears that the main command was not executed but the echo command was executed. If I run the main command standalone in Windows Terminal as shown, the command works as desired:

>>> C:\Users\jgoss\eclipse\committers-2019-09\eclipse\eclipse.exe -data C:\SharedData\Projects\Tutorial &

I simply cut and paste the contents of the first command in the script block and it worked as I want. The program eclipse.exe was started in the background. Why does this not work within a script block?

1
  • 1
    The first command in your Scriptblock $sp is actually a write-output "...". Maybe you take a look at the start-process cmdlet or use the ampersand & symbol. Commented Oct 20, 2019 at 15:29

1 Answer 1

1

This would get it to work, but there are easier ways to do it. I'm using notepad as an example anyone can reproduce.

$hm = "c:\windows\system32"
$eclipse_path = "$hm\notepad.exe"
$sp = {
  & $eclipse_path c:\users\js\foo\note.ps1
  Write-Host "Eclipse starting" } 
Invoke-Command -ScriptBlock $sp

For example in your $profile you can add the eclipse folder to your path:

$eclipse_path = "$home\eclipse\committers-2019-09\eclipse"
$env:path += $eclipse_path

Then you could simply run eclipse and whatever filename. You could use control-r to search the command history for the last time you ran it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.