Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - inconsistent behavior

Reply
 
Old 08-20-2008   #1 (permalink)
rmq
Guest


 
 

inconsistent behavior

In powershell console, I typed "calc", then "windows caculator"
appear, then powershell immediately returned and I could type other
commands, though "windows caculator" are still running.

But if I wrote the following code in VS, I must manually close
"windows caculator" first, the Main function return.

So, why the behaviors are inconsistent?

using ....
namespace Host3 {
class Program {
static void Test2() {
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline("calc");
pipeline.Invoke();
runspace.Close();
}
static void Main(string[] args) {
Test2();
}
}
}

My System SpecsSystem Spec
Old 08-20-2008   #2 (permalink)
tojo2000
Guest


 
 

Re: inconsistent behavior

On Aug 19, 11:40*pm, rmq <zhangf...@xxxxxx> wrote:
Quote:

> In powershell console, I typed "calc", then "windows caculator"
> appear, then powershell immediately returned and I could type other
> commands, though "windows caculator" are still running.
>
> But if I wrote the following code in VS, I must manually close
> "windows caculator" first, the Main function return.
>
> So, why the behaviors are inconsistent?
>
> using ....
> namespace Host3 {
> * * class Program {
> * * * * static void Test2() {
> * * * * * * Runspace runspace = RunspaceFactory.CreateRunspace();
> * * * * * * runspace.Open();
> * * * * * * Pipeline pipeline = runspace.CreatePipeline("calc");
> * * * * * * pipeline.Invoke();
> * * * * * * runspace.Close();
> * * * * }
> * * * * static void Main(string[] args) {
> * * * * * * Test2();
> * * * * }
> * * }
>
> }
My C# foo isn't terribly strong, but I believe the problem is that
you're creating a pipeline that is going to keep waiting for output
from the command, because rather than just spawning a process you're
holding open the pipeline for it.

The same thing happens if you type this in at the prompt:

calc | select *

Your command won't return until calc.exe exits because the pipeline is
waiting for objects.
My System SpecsSystem Spec
Old 08-21-2008   #3 (permalink)
rmq
Guest


 
 

Re: inconsistent behavior

On Aug 20, 4:38*pm, tojo2000 <tojo2...@xxxxxx> wrote:
Quote:

> On Aug 19, 11:40*pm, rmq <zhangf...@xxxxxx> wrote:
>
>
>
Quote:

> > In powershell console, I typed "calc", then "windows caculator"
> > appear, then powershell immediately returned and I could type other
> > commands, though "windows caculator" are still running.
>
Quote:

> > But if I wrote the following code in VS, I must manually close
> > "windows caculator" first, the Main function return.
>
Quote:

> > So, why the behaviors are inconsistent?
>
Quote:

> > using ....
> > namespace Host3 {
> > * * class Program {
> > * * * * static void Test2() {
> > * * * * * * Runspace runspace = RunspaceFactory.CreateRunspace();
> > * * * * * * runspace.Open();
> > * * * * * * Pipeline pipeline = runspace.CreatePipeline("calc");
> > * * * * * * pipeline.Invoke();
> > * * * * * * runspace.Close();
> > * * * * }
> > * * * * static void Main(string[] args) {
> > * * * * * * Test2();
> > * * * * }
> > * * }
>
Quote:

> > }
>
> My C# foo isn't terribly strong, but I believe the problem is that
> you're creating a pipeline that is going to keep waiting for output
> from the command, because rather than just spawning a process you're
> holding open the pipeline for it.
>
> The same thing happens if *you type this in at the prompt:
>
> calc | select *
>
> Your command won't return until calc.exe exits because the pipeline is
> waiting for objects.
I agree with you , because the host application does not need a return
value, so host return to prompt quickly.
but do you know how to config and make the host must wait "calc"
return?
thx
My System SpecsSystem Spec
Old 08-21-2008   #4 (permalink)
tojo2000
Guest


 
 

Re: inconsistent behavior

On Aug 21, 1:25*am, rmq <zhangf...@xxxxxx> wrote:
Quote:

> On Aug 20, 4:38*pm, tojo2000 <tojo2...@xxxxxx> wrote:
>
>
>
Quote:

> > On Aug 19, 11:40*pm, rmq <zhangf...@xxxxxx> wrote:
>
Quote:
Quote:

> > > In powershell console, I typed "calc", then "windows caculator"
> > > appear, then powershell immediately returned and I could type other
> > > commands, though "windows caculator" are still running.
>
Quote:
Quote:

> > > But if I wrote the following code in VS, I must manually close
> > > "windows caculator" first, the Main function return.
>
Quote:
Quote:

> > > So, why the behaviors are inconsistent?
>
Quote:
Quote:

> > > using ....
> > > namespace Host3 {
> > > * * class Program {
> > > * * * * static void Test2() {
> > > * * * * * * Runspace runspace = RunspaceFactory.CreateRunspace();
> > > * * * * * * runspace.Open();
> > > * * * * * * Pipeline pipeline = runspace.CreatePipeline("calc");
> > > * * * * * * pipeline.Invoke();
> > > * * * * * * runspace.Close();
> > > * * * * }
> > > * * * * static void Main(string[] args) {
> > > * * * * * * Test2();
> > > * * * * }
> > > * * }
>
Quote:
Quote:

> > > }
>
Quote:

> > My C# foo isn't terribly strong, but I believe the problem is that
> > you're creating a pipeline that is going to keep waiting for output
> > from the command, because rather than just spawning a process you're
> > holding open the pipeline for it.
>
Quote:

> > The same thing happens if *you type this in at the prompt:
>
Quote:

> > calc | select *
>
Quote:

> > Your command won't return until calc.exe exits because the pipeline is
> > waiting for objects.
>
> I agree with you , because the host application does not need a return
> value, so host return to prompt quickly.
> but do you know how to config and make the host must wait "calc"
> return?
> thx
Like I said, my C# skills aren't the greatest, but does this help?
http://www.c-sharpcorner.com/UploadF...mandsInCS.aspx
My System SpecsSystem Spec
Old 08-21-2008   #5 (permalink)
rmq
Guest


 
 

Re: inconsistent behavior

On Aug 21, 5:13*pm, tojo2000 <tojo2...@xxxxxx> wrote:
Quote:

> On Aug 21, 1:25*am, rmq <zhangf...@xxxxxx> wrote:
>
>
>
Quote:

> > On Aug 20, 4:38*pm, tojo2000 <tojo2...@xxxxxx> wrote:
>
Quote:
Quote:

> > > On Aug 19, 11:40*pm, rmq <zhangf...@xxxxxx> wrote:
>
Quote:
Quote:

> > > > In powershell console, I typed "calc", then "windows caculator"
> > > > appear, then powershell immediately returned and I could type other
> > > > commands, though "windows caculator" are still running.
>
Quote:
Quote:

> > > > But if I wrote the following code in VS, I must manually close
> > > > "windows caculator" first, the Main function return.
>
Quote:
Quote:

> > > > So, why the behaviors are inconsistent?
>
Quote:
Quote:

> > > > using ....
> > > > namespace Host3 {
> > > > * * class Program {
> > > > * * * * static void Test2() {
> > > > * * * * * * Runspace runspace = RunspaceFactory.CreateRunspace();
> > > > * * * * * * runspace.Open();
> > > > * * * * * * Pipeline pipeline = runspace.CreatePipeline("calc");
> > > > * * * * * * pipeline.Invoke();
> > > > * * * * * * runspace.Close();
> > > > * * * * }
> > > > * * * * static void Main(string[] args) {
> > > > * * * * * * Test2();
> > > > * * * * }
> > > > * * }
>
Quote:
Quote:

> > > > }
>
Quote:
Quote:

> > > My C# foo isn't terribly strong, but I believe the problem is that
> > > you're creating a pipeline that is going to keep waiting for output
> > > from the command, because rather than just spawning a process you're
> > > holding open the pipeline for it.
>
Quote:
Quote:

> > > The same thing happens if *you type this in at the prompt:
>
Quote:
Quote:

> > > calc | select *
>
Quote:
Quote:

> > > Your command won't return until calc.exe exits because the pipeline is
> > > waiting for objects.
>
Quote:

> > I agree with you , because the host application does not need a return
> > value, so host return to prompt quickly.
> > but do you know how to config and make the host must wait "calc"
> > return?
> > thx
>
> Like I said, my C# skills aren't the greatest, but does this help?http://www.c-sharpcorner.com/UploadF...llCommandsInCS...
Thank you tojo2000 for your great help!!
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Solved Inconsistent Picture Preview Behavior General Discussion
Re: Inconsistent behavior with color rules Live Mail
Baffled by Inconsistent and Irrational Vista Backup Behavior Vista performance & maintenance
ADSI Inconsistent behavior PowerShell
Smart-quote behavior: Is current behavior ideal? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46