Jump to content
Software FX Community

-refresh within script block does not work


Recommended Posts

What you're doing is simply wrapping the commands so they run in their own scope (reference: http://blogs.msdn.com/powershell/archive/2007/03/07/invoke-expression.aspx).

I feel like I'm missing what you're trying to accomplish...  Why doesn't simply using 'get-date|out-gauge -refresh 0:0:1' not do what you're looking for?

Are you specifically looking to use get-date for more processing outside of that particular line?

[Edited Wednesday, August 08, 2007 7:16:15 AM AST]

Link to comment
Share on other sites

What I am trying to do is in your reference link. [;)]

I use start-demo function mentioned in that blog post to automate demo. Start-demo reads one-liners from text file and invoke them line by line. As written in the post, it invokes command line like following,

Invoke-Expression $(".{" + $_lines[$_i] + "}| out-host")

$_lines holds one-liners read from text file.

When I added 'get-date|out-gauge -refresh 0:0:1' to my demo commands for example, out-gauge shows error I wrote earlier. Out-gauge was invoked as

.{ get-date | out-gauge -refresh 0:0:1 } | out-host

While following invokes out-gauge -refresh without error.

Invoke-Expression $(".{`n" + $_lines[$_i] + "}| out-host")

Actual lines would be

{

get-date | out-gauge -refresh 0:0:1 } | out-host

 

Link to comment
Share on other sites

Now I follow you...  The issue seems to be directly with -refresh.  When you call -refresh, what happens is that there is an invokation of another PowerShell runspace.  The entire command is passed to the new runspace, except it is cutoff just after the time value, so the "{" is included, but the "}" is not included in what is used by the new runspace.

I never tried the start-demo script with -refresh so thanks for pointing that out!

Would this be an acceptable workaround...  Add something like this to your demo.txt file:

set-content start-gadget.ps1 "get-date|out-gauge -type digital -refresh 0:0:01"get-content start-gadget.ps1./start-gadget

Basically, start-demo is going to write the commands to a file.  Using set-content will make sure to overwrite if anything is already in that file everytime start-demo is invoked.

You may want to use .NET to get a temporary file name, and use that instead?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...