![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | "@Echo" behavior in PS scripts Hi everyone, writing my first script after 3 years I wanted to implement alsodifferent logs in it - event log support, overview log and debug log (this script will run as scheduled task). Event log and overview log are not problem. For debug log, I wanted to save full output to log file, so in case of any problems I could just check this "last session" log file. To my surprise I realized PowerShell behaves like "@Echo Off" in old batches - is there any way to switch it full output?? Thanks, Martin |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: "@Echo" behavior in PS scripts BTW idea behind is pretty simply, I just want to use Start-Transcript to create debug log of whole script execution ![]() In batches I used MTee for this purpose... Martin "Martin Zugec" <martin.zugec@xxxxxx> wrote in message news:%2339fP$O3IHA.4164@xxxxxx
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) |
| Scripting Guru ![]() Rep Power: 8 ![]() ![]() ![]() | Re: "@Echo" behavior in PS scripts So does Start-Transcript solve your problem or is there still an issue here? |
My System Specs![]() |
| | #4 (permalink) | ||||||||||||
| Guest | Re: "@Echo" behavior in PS scripts Well it doesn't work of course. In batches: - Default - output everything to console - @Echo off - output only stdout\strerr In PowerShell - Default - output only stdout\strerr - ??? Consider example with Hello world. HelloWorld.cmd: Echo Hello World Output: C:\>HelloWorld.cmd C:\>Echo Hello world Hello world C:\> HelloWorld.ps1 "Hello world" Output: PS C:\> .\HelloWorld.ps1 Hello world In .cmd, I can change this behavior by using @Echo off\on. But how to change it in powershell - I don't know ![]() Martin "sapienscripter" <guest@xxxxxx-email.com> wrote in message news:a25cf76794efcfd28645d2dee62b7ee7@xxxxxx-gateway.com...
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #5 (permalink) |
| Scripting Guru ![]() Rep Power: 8 ![]() ![]() ![]() | Re: "@Echo" behavior in PS scripts The first change is to start thinking of PowerShell as object oriented. While there is a console, it does not behave (obviously) like the CMD shell. When you run a PowerShell command, objects are sent through the pipeline. At the end of pipeline are default cmdlets that take the remaining objects in the pipeline and present a text display. I can't think of a way to mimic the echo off/echo on technique in PowerShell. There are cmdlets you can use to save output to a file like Out-File. You might also look at Tee-Object which saves output to a file and displays it to the console. However, none of these will also capture the actual command. For that you would need to use Start-Transcript. If you wanted a good log when running a script or function, I would add this cmdlet at the beginning to start logging and then turn it off at the end with Stop-Transcript. |
My System Specs![]() |
| | #6 (permalink) | ||||||||||||||||||||||||
| Guest | Re: "@Echo" behavior in PS scripts Try this function and see if you like it. function `@echo ([switch]$off){if($off){stop-transcript}else{start-transcript}} # helloworld.ps1 `@echo write-Host "Hello" write-Host "World" `@echo -off This is not exactly the same, but should give you what you want. "Martin Zugec" <martin.zugec@xxxxxx> wrote in message news:uPYdUYQ3IHA.3508@xxxxxx
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #7 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: "@Echo" behavior in PS scripts Hi Brandon, first try that Hello world example Start-Transcript works fine - problemI have is that PowerShell acts differently when it is running in interactive session (do something, prompt, read prompt, do something, prompt, read prompt) and something completely different when running from .ps1 file. So transcript will only save stdout\strerr (which makes sense). I know it sounds really really strange, but old cmd.exe was maybe more flexible here ![]() Martin "Brandon [MVP]" <tshell.mask@xxxxxx> wrote in message news:7F072624-8B9C-4E65-AB5B-BDF07368125B@xxxxxx
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #8 (permalink) | ||||||||||||
| Guest | Re: "@Echo" behavior in PS scripts Heya, same reply as for Brandon - problem is not how to do it, its pretty fine (either Start-Transcript or Tee-Object), problem is that when you run .ps1 script, there is (as far as I know) no way how to difine verbosity of that script (stdin\strout or full). I am afraid this have nothing to do with object-orientation of PowerShell. Martin "sapienscripter" <guest@xxxxxx-email.com> wrote in message news:55c88dba1fc41dfc1abe7aaf3e6da755@xxxxxx-gateway.com...
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #9 (permalink) |
| Scripting Guru ![]() Rep Power: 8 ![]() ![]() ![]() | Re: "@Echo" behavior in PS scripts You are trying to impose essentially text based techniques on an object oriented shell and it won't work. At the interactive level, you'll need to use Start-Transcript. One thing I just discovered is that Echo is an alias for Write-Output. |
My System Specs![]() |
| | #10 (permalink) |
| Scripting Guru ![]() Rep Power: 8 ![]() ![]() ![]() | Re: "@Echo" behavior in PS scripts The more I read this thread the more I'm not sure what you are really after. It seems that when using a script in PowerShell the transcript technique will meet your needs. Is that correct? When it comes to the interactive shell I think you still have an issue. Can you give a more practical example of something you would do in the CMD shell that you are trying to recreate in PowerShell? Something other than "hello world". |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Unwanted Multiple contacts in "To","CC","BCC" of email send catago | xsailer | Vista mail | 1 | 07-26-2008 08:34 AM |
| Vista not wotking with "My Computer" or "Control Panel", "Screen Saver" | Platebanger | Vista General | 6 | 02-05-2008 08:54 AM |
| Incorrect behavior of GPO "Access this computer from the network" | HAL | Vista General | 1 | 06-04-2007 03:21 AM |
| WM5 Sync with Vista "Windows Calender", "Contacts", and "Mail" | Tony | Vista General | 1 | 02-16-2007 06:20 PM |
| "Close Lid behavior" broken | Jon Davis | Vista General | 29 | 01-02-2007 02:21 PM |