Shigeya Tanabe Posted August 7, 2007 Report Share Posted August 7, 2007 When I tried this script, &{get-date | out-gauge -refresh 0:0:1} An error icon appears on the gauge which says closing "}" is missing. I guess out-gauge captures commands before pipe so that error would be reasonable. Any workaround to use refreshing commands within a single line script block? Link to comment Share on other sites More sharing options...
marco.shaw Posted August 7, 2007 Report Share Posted August 7, 2007 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 More sharing options...
Shigeya Tanabe Posted August 8, 2007 Author Report Share Posted August 8, 2007 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 More sharing options...
marco.shaw Posted August 8, 2007 Report Share Posted August 8, 2007 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 More sharing options...
Shigeya Tanabe Posted August 13, 2007 Author Report Share Posted August 13, 2007 Thanks for your detail! Now the situation I encounter is clear. And thanks for your workaround too. I tried to use function start-gadget { xxx } instead of your idea, however it does not work. So, set/get-content is the best I think. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.