Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Log command output to a file

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 02-08-2007   #1 (permalink)
Romu
Guest


 

Log command output to a file

Hi all,
I'm facing so much differences by running PS1 files within
PowershellAnalyzer or in a PS prompt that's incredible !!

I want to log a call to a command line program, I wrote:
Invoke-Expression -command $run | out-file $log -encoding ASCII

This works perfectly within PowershellAnalyzer, in a PS prompt, the log file
is well created but remains empty. Why ??

Thanks for your help.

My System SpecsSystem Spec
Old 02-08-2007   #2 (permalink)
RichS
Guest


 

RE: Log command output to a file

what does $run actually equal? without knowing what you are trying to invoke
its difficult to answer the question.

There seem to be a number of differences between running in Powershell
Analyzer & in a PS console. I believe PA hosts a PowerShell instance so I
can only suggest that the differences are due to the interaction of PA and
PowerShell. It would be worth reporting this to the PowerShell Analyzer site
so they can have a look at it as well
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Romu" wrote:

> Hi all,
> I'm facing so much differences by running PS1 files within
> PowershellAnalyzer or in a PS prompt that's incredible !!
>
> I want to log a call to a command line program, I wrote:
> Invoke-Expression -command $run | out-file $log -encoding ASCII
>
> This works perfectly within PowershellAnalyzer, in a PS prompt, the log file
> is well created but remains empty. Why ??
>
> Thanks for your help.

My System SpecsSystem Spec
Old 02-08-2007   #3 (permalink)
Romu
Guest


 

RE: Log command output to a file

Thanks for this answer Richard, the $run variable in this case is a call to
or Starteam configuration management system.

The command string looks like:
stcmd hist -x -stop -nologo -p....

And when run in a PS prompt, this command sends some messages to the std
output.

And you're right, I'm going to warn the PSAnalyzer guys beside this thread.

"RichS" wrote:

> what does $run actually equal? without knowing what you are trying to invoke
> its difficult to answer the question.
>
> There seem to be a number of differences between running in Powershell
> Analyzer & in a PS console. I believe PA hosts a PowerShell instance so I
> can only suggest that the differences are due to the interaction of PA and
> PowerShell. It would be worth reporting this to the PowerShell Analyzer site
> so they can have a look at it as well
> --
> Richard Siddaway
> Please note that all scripts are supplied "as is" and with no warranty
> Blog: http://richardsiddaway.spaces.live.com/
> PowerShell User Group: http://www.get-psuguk.org.uk
>
>
> "Romu" wrote:
>
> > Hi all,
> > I'm facing so much differences by running PS1 files within
> > PowershellAnalyzer or in a PS prompt that's incredible !!
> >
> > I want to log a call to a command line program, I wrote:
> > Invoke-Expression -command $run | out-file $log -encoding ASCII
> >
> > This works perfectly within PowershellAnalyzer, in a PS prompt, the log file
> > is well created but remains empty. Why ??
> >
> > Thanks for your help.

My System SpecsSystem Spec
Old 02-08-2007   #4 (permalink)
William Stacey [C# MVP]
Guest


 

Re: Log command output to a file

This seems to work. May be something with what is inside $run var (maybe
another redirection).

PS C:\TEMP> $run = "dir"
PS C:\TEMP> $log = "c:\temp\log.txt"
PS C:\TEMP> invoke-expression $run | out-file $log -en ascii

--
William Stacey [C# MVP]
PCR concurrency library: www.codeplex.com/pcr
PSH Scripts Project www.codeplex.com/psobject


"Romu" <Romu@discussions.microsoft.com> wrote in message
news:AAE92541-CC33-4336-B21B-B515C824C38A@microsoft.com...
| Hi all,
| I'm facing so much differences by running PS1 files within
| PowershellAnalyzer or in a PS prompt that's incredible !!
|
| I want to log a call to a command line program, I wrote:
| Invoke-Expression -command $run | out-file $log -encoding ASCII
|
| This works perfectly within PowershellAnalyzer, in a PS prompt, the log
file
| is well created but remains empty. Why ??
|
| Thanks for your help.


My System SpecsSystem Spec
Old 02-08-2007   #5 (permalink)
Brandon Shell
Guest


 

Re: Log command output to a file

In PA you use a run space. Each run space maintains its variables,
functions, and settings. I would guess you keep PA all the time or at least
quite a bit more than you do Posh Console. I guess my point is that it is
possible that you have defined $run different in PA than in the Console.
That would indeed change what is put in the file.

That said... I understand the frustration.

--
Brandon Shell
---------------
Stop by my blog some time
http://www.bsonposh.com/
Try the "Search of Powershell Blogs"
--------------------------------------

"Romu" <Romu@discussions.microsoft.com> wrote in message
news:AAE92541-CC33-4336-B21B-B515C824C38A@microsoft.com...
> Hi all,
> I'm facing so much differences by running PS1 files within
> PowershellAnalyzer or in a PS prompt that's incredible !!
>
> I want to log a call to a command line program, I wrote:
> Invoke-Expression -command $run | out-file $log -encoding ASCII
>
> This works perfectly within PowershellAnalyzer, in a PS prompt, the log
> file
> is well created but remains empty. Why ??
>
> Thanks for your help.


My System SpecsSystem Spec
Old 02-08-2007   #6 (permalink)
Romu
Guest


 

Re: Log command output to a file

I agree William, it works. I check.

"William Stacey [C# MVP]" wrote:

> This seems to work. May be something with what is inside $run var (maybe
> another redirection).
>
> PS C:\TEMP> $run = "dir"
> PS C:\TEMP> $log = "c:\temp\log.txt"
> PS C:\TEMP> invoke-expression $run | out-file $log -en ascii
>
> --
> William Stacey [C# MVP]
> PCR concurrency library: www.codeplex.com/pcr
> PSH Scripts Project www.codeplex.com/psobject
>
>
> "Romu" <Romu@discussions.microsoft.com> wrote in message
> news:AAE92541-CC33-4336-B21B-B515C824C38A@microsoft.com...
> | Hi all,
> | I'm facing so much differences by running PS1 files within
> | PowershellAnalyzer or in a PS prompt that's incredible !!
> |
> | I want to log a call to a command line program, I wrote:
> | Invoke-Expression -command $run | out-file $log -encoding ASCII
> |
> | This works perfectly within PowershellAnalyzer, in a PS prompt, the log
> file
> | is well created but remains empty. Why ??
> |
> | Thanks for your help.
>
>
>

My System SpecsSystem Spec
Old 02-08-2007   #7 (permalink)
klumsy@gmail.com
Guest


 

Re: Log command output to a file

i agree with brandon, this is likely the case. I can't see anyreason
why powershell analyzer and powershell.exe would behave differently in
this case. Mostly powershell analyzer will behave differently in cases
when you are dealing with native console out, or native console in..
but for straight commands it shouldn't.. though of course if it is, i
want to know.

Karl
http://www.powershellanalyzer.com

My System SpecsSystem Spec
Old 02-09-2007   #8 (permalink)
Romu
Guest


 

Re: Log command output to a file

Good to see you here Karl, I saw several differences between running a PS1 in
PSA or PS prompt, the first one is the subject of this thread, the second one
is just bere below.

I wrote something like :

$var = @{
'child' = "child1"
'child2' = $var.child + "child2"
}

$var.child2

In PSA, the result is: child1child2
In PS prompt: child2

The PS prompt doesn't resolve variables as PSA does, I guess this could from
the same thing as my $run problem.


"klumsy@gmail.com" wrote:

> i agree with brandon, this is likely the case. I can't see anyreason
> why powershell analyzer and powershell.exe would behave differently in
> this case. Mostly powershell analyzer will behave differently in cases
> when you are dealing with native console out, or native console in..
> but for straight commands it shouldn't.. though of course if it is, i
> want to know.
>
> Karl
> http://www.powershellanalyzer.com
>
>

My System SpecsSystem Spec
Old 02-09-2007   #9 (permalink)
Brandon Shell
Guest


 

Re: Log command output to a file

maybe a stupid question, but did you run it more than once?

I sometimes forget that I have defined a variable before. Remembering that
PA maintains the runspace even if you use it as IDE. When you write a script
and run it... the data persist.

--
Brandon Shell
---------------
Stop by my blog some time
http://www.bsonposh.com/
Try the "Search of Powershell Blogs"
--------------------------------------
"Romu" <Romu@discussions.microsoft.com> wrote in message
news:0F36ECD5-BD3C-4B6F-9F4A-2F1F9CE08D45@microsoft.com...
> Good to see you here Karl, I saw several differences between running a PS1
> in
> PSA or PS prompt, the first one is the subject of this thread, the second
> one
> is just bere below.
>
> I wrote something like :
>
> $var = @{
> 'child' = "child1"
> 'child2' = $var.child + "child2"
> }
>
> $var.child2
>
> In PSA, the result is: child1child2
> In PS prompt: child2
>
> The PS prompt doesn't resolve variables as PSA does, I guess this could
> from
> the same thing as my $run problem.
>
>
> "klumsy@gmail.com" wrote:
>
>> i agree with brandon, this is likely the case. I can't see anyreason
>> why powershell analyzer and powershell.exe would behave differently in
>> this case. Mostly powershell analyzer will behave differently in cases
>> when you are dealing with native console out, or native console in..
>> but for straight commands it shouldn't.. though of course if it is, i
>> want to know.
>>
>> Karl
>> http://www.powershellanalyzer.com
>>
>>


My System SpecsSystem Spec
Old 02-09-2007   #10 (permalink)
Romu
Guest


 

Re: Log command output to a file

Yes Brandon, I run it several times, so now I know persists some variable,
I'll take care.

Have a look at a second interesting test in this thread, I answered my first
question.

And thanks for your help.

"Brandon Shell" wrote:

> maybe a stupid question, but did you run it more than once?
>
> I sometimes forget that I have defined a variable before. Remembering that
> PA maintains the runspace even if you use it as IDE. When you write a script
> and run it... the data persist.
>
> --
> Brandon Shell
> ---------------
> Stop by my blog some time
> http://www.bsonposh.com/
> Try the "Search of Powershell Blogs"
> --------------------------------------
> "Romu" <Romu@discussions.microsoft.com> wrote in message
> news:0F36ECD5-BD3C-4B6F-9F4A-2F1F9CE08D45@microsoft.com...
> > Good to see you here Karl, I saw several differences between running a PS1
> > in
> > PSA or PS prompt, the first one is the subject of this thread, the second
> > one
> > is just bere below.
> >
> > I wrote something like :
> >
> > $var = @{
> > 'child' = "child1"
> > 'child2' = $var.child + "child2"
> > }
> >
> > $var.child2
> >
> > In PSA, the result is: child1child2
> > In PS prompt: child2
> >
> > The PS prompt doesn't resolve variables as PSA does, I guess this could
> > from
> > the same thing as my $run problem.
> >
> >
> > "klumsy@gmail.com" wrote:
> >
> >> i agree with brandon, this is likely the case. I can't see anyreason
> >> why powershell analyzer and powershell.exe would behave differently in
> >> this case. Mostly powershell analyzer will behave differently in cases
> >> when you are dealing with native console out, or native console in..
> >> but for straight commands it shouldn't.. though of course if it is, i
> >> want to know.
> >>
> >> Karl
> >> http://www.powershellanalyzer.com
> >>
> >>

>
>

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
capture command and its output hugh PowerShell 1 02-16-2008 08:40 AM
Split output to command swyck PowerShell 3 12-03-2007 03:44 PM
Command output to file André Landreau Vista file management 3 11-20-2007 04:54 PM
How to catch a command output ? Romu PowerShell 2 01-22-2007 09:10 AM
Output Event Log From Command Line =?Utf-8?B?c2VucmFiZGV0?= Vista General 4 08-14-2006 09:23 PM


Vistax64.com 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 2005-2008

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 47 48 49 50 51