Controlling PowerShell's console output

How do you control PowerShell's console output and overwrite the last character written?
I want to overwrite a character with a loop, like the spinning baton in UNIX while some Job.status -eq running. You know like cycle through |/-\| so it looks like a spinning bar.
I have the loop written but the console never seems to want to overwrite the last chacter. I am using write-host -nonewline, so at least I'm on the right line.
I have tried using `b and then the write-host, but it actually get this box character written to the screen instead of a backspace.
I have tried using [console]::cursor stuff but I can't set the cursor to less than zero and zero just leaves the cursor where it was anyway.
I also tried using [string]::format and {0,1} type stuff, but it always writes next to the last character. There's a guy who wrote a countdown timer, and when I run his code it doesn't work for me (http://poshtips.com/2010/03/29/powershell-countdown-timer/).
The timer just keeps writing to the side after 40 whitespaces.
The only way I have been able to do it is by calling cls before each character; of course i'd rather not clear the entire screen.
I'm hoping you will enlighten me...

function myWaitJob($job) {
$saveY = [console]::CursorTop
$saveX = [console]::CursorLeft
$str = '|','/','-','\'
do {
$str | ForEach-Object { Write-Host -Object $_ -NoNewline
Start-Sleep -Milliseconds 100
[console]::setcursorposition($saveX,$saveY)
} # end foreach-object
if ((Get-Job -Name $job).state -eq 'Running')
{$running = $true}
else {$running = $false}
} # end do
while ($running)
} # end function
Start-Job -ScriptBlock {Start-Sleep 10} -Name j1
myWaitJob j1
rjb j1
[string](0..9|%{[char][int](32+("39826578840055658268").substring(($_*2),2))})-replace "\s{1}\b"

Similar Messages

  • I want to show console output in my cmd prompt in C# winform application

    Hi,
    I'm launching the some process in C# .net Winform appliaction. But i couldn't able to see console output on the screen. The process is getting launched but inside cmd prompt window, it is showing nothing. I would like to show something on cmd prompt. Please
    help on this.
     using (Process comxdcProcess = new System.Diagnostics.Process())
                            comxdcProcess.StartInfo.FileName = fileName;
                            comxdcProcess.StartInfo.Arguments = args;
                            comxdcProcess.StartInfo.RedirectStandardError = true;
                            comxdcProcess.StartInfo.RedirectStandardOutput = true;
                            comxdcProcess.StartInfo.UseShellExecute = false;
                            comxdcProcess.Start();
                            this.errorComment = comxdcProcess.StandardError.ReadToEnd();
                            StreamReader myStreamReader = comxdcProcess.StandardOutput;
                            //// Read the standard output of the spawned process. 
                            this.errorComment = myStreamReader.ReadToEnd();
                            comxdcProcess.WaitForExit();
    click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you Happy Programming! Hari

    @Hariprasadbrk
    Do you mean you have use process class to start "cmd prompt" And want to display some output in it?
    If so, there is no need to use RedirectStandardOutput property. This property means the output of an application is written to the
    Process.StandardOutput stream.
    // Setup the process with the ProcessStartInfo class.
    ProcessStartInfo start = new ProcessStartInfo();
    start.FileName = @"C:\7za.exe"; // Specify exe name not cmd exe.
    start.UseShellExecute = false;
    start.RedirectStandardOutput = true;
    // Start the process.
    using (Process process = Process.Start(start))
    // Read in all the text from the process with the StreamReader.
    using (StreamReader reader = process.StandardOutput)
    string result = reader.ReadToEnd();
    Console.Write(result);
    Output
    This section shows the output of the process.
    7-Zip (A) 4.60 beta Copyright (c) 1999-2008 Igor Pavlov 2008-08-19
    Usage: 7za <command> [<switches>...] <archive_name> [<file_names>...]
    [<@listfiles...>]
    So you can start a cmd exe.
    Please also take a look at the article from codeproject
    How to redirect Standard Input/Output of an application
    In summary, the shutdown proces is invoked from my application, and it displays the output from the process in RichTextBox control.
    Have a nice day!
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How can i display console outputs in my form?

    Hi,
    <p>I have an application which performs some actions like, insert 200 rows in the database. While inserting data i am using <code>
    int i=0;
    system.out.println ("Insert "+i+" row in database");
    i=i+1;
    </code>
    The output displays on the commnad line.</p>
    <p>what i am trying to do is i have a form, which has text area. I want to display the console output "Insert 1 row in database" and next "Insert 2 row in database"..... and soon in the text area. How could i do that?</p>
    <p>Thanks in advance!!</p>

    Hi Petes,
    Thanks for you response. I am very new to java. I just started learning jsp and have bit knowledge of swing. I am confused how to use jsp and swing componenets together. Can you please guide me a bit?
    Also i am using AJAX to update form field. I am able to work with the rest except bringing the console output in the text area.
    Do you think i have some other way to do it?
    Do you think, it is a good idea , if I will save the output strings in a file and with the help of jsp i can read the file in textarea.
    Pin2g

  • How can i display console outputs in my form field?

    Hi,
    I have an application which performs some actions like, insert 200 rows in the database. While inserting data i am using
    int i=0;
    system.out.println ("Insert "+i+" row in database");
    i=i+1;
    The output displays on the commnad line
    what i am trying to do is i have a form, which has text area. I want to display the console output "Insert 1 row in database" and next "Insert 2 row in database"..... and soon in the text area. How could i do that?
    Thanks in advance!!
    pin2g

    solution removed, because you crossposted.
    Message was edited by:
    Navy_Coder

  • How to print console output

    Hi, I have a JSP page and I would like to print STDOUT to the page. Is this possible?
    I've seen a few methods and none work for me:
    BufferedReader reader = new BufferedReader(System.out);
    String input = reader.readLine();
    out.println(input);*** Error: Type BufferedReader was not found.
    FileOutputStream out;
                    PrintStream ps; // declare a print stream object
                    try {
                     // Create a new file output stream
                    out = new FileOutputStream("myfile.txt");
                            // Connect print stream to the output stream
                            ps = new PrintStream(out);
                            ps.println ("This data is written to a file:");
                System.err.println ("Write successfully");
                            ps.close();
                    catch (Exception e){
                            System.err.println ("Error in writing to file");
                    }*** Error: Duplicate declaration of local variable "out".
    *** Error: The type of the left-hand side in this assignment, "javax/servlet/jsp/JspWriter", is not compatible with the type of the right-hand side expression, "java/io/FileOutputStream".
    *** Error: No match was found for constructor "PrintStream(javax.servlet.jsp.JspWriter)".
    So what's next?
    How can I call the console without writing to a file first?
    I would like AJAX to show console output in real-time.

    Thanks for your help.
    The reason I have the script to write to a file is because it's the closest I could find to what I want. Ideally, I would be able to run a script that prints to the console but I want to grab the system.out going to the console and display it on the page.
    Basically, I want the page to act as a console but not redirect the output (I want it to still go to the console) and I don't want it in a text file that the page reads.
    So for example, the page loads and while that is occurring, the server grabs the console output and prints to the page. Then I run a function on the page that prints to the console and on the refresh, print the updated output. Ideally, I would restrict the output that was relevant to the page's functions and ignore every output to the console but I'm not (trying to be) picky.
    So how would that work?
    Pseudo-code:
    for (int i=0;i < System.out().length(); i++) {
            String grabbedtext += System.out().toString();
    }out.println(grabbedtext);

  • Server console output

    Hi,
    I have been using flex from last six month. I have develped one application and now its time to deploy the application. But, I am facing one issue regarding server console output. In my application I have various remote call to java class deployed on JBOSS server. My problem is that, whenever I made any remote call the information of that remote call gets printed on server console. I want to stop this server console printing. How can I do this? Please suggest. I have checked in my code, there is no trace() or system.out.println() command is used. Please help me out of this. Its very urgent.
    Thanks.
    Regards,
    Ravindar Kumar

    Hi
    You can setup properties so that we can save stdout and stderr to files.
    In the setDomainEnv.cmd file of your domain, you can set the properties so that the ouput will be saved to a file
    %WLS_STDOUT_LOG%
    %WLS_STDERR_LOG%
    Vimala-

  • Create console output from LabView

    Hi all.
    Is there any way of creating a console string output when calling a dll from LabView?
    I have to call a C++ program from LabView and I'm using a dll. I need to debug this program, and I think that using "cout" is the fastest and simplest way.
    Thanks in advance.
    Regards,
    Francisco

    No, there is no console output when calling a DLL. You could have your DLL simply write debug information to a log file.

  • Control panel and Console not working

    Hi,
    I have installed various Java Runtime Environments, all of which run applets flawlessly. There is one problem though, I need to enter an application that needs a certificate for security, and the dialog opens as a blank screen. I'm not positive, but it is similar to when I open the control panel and the console; a blank screen. Is there a way to fix the control panel and console so it doesn't show up as a blank screen, short of reinstalling the OS? I am thinking if I fix the control panel, it might fix the security dialog.
    System: XP SP1

    I have noticed that when i maximize a window that is blank ( i.e. the console or java web start) the screen refreshes and the window is displayed.

  • How to see console output in Sun Java(TM) System Web Server 6.1 SP7?

    Dear All,
    I am having Sun Java(TM) System Web Server 6.1 SP7 installed on Windows 2000 Prof.
    I have deployed few applications and they were running successfully.
    From debugging point of view, i like to see the output from System.out.println .
    Prior to SP7 there is a console which shows this output. But now the batch files only starts and stops the admin and site server services. Where to see for console output?
    Is there command like tail.exe of Weblogic awailable for Sun Java System Web Server or any setting to be done in Admin?
    Please revert.
    -Sameer

    Response headers can be found in srvhdrs pblock.
    Those can be manipulated by using set-variable
    http://docs.sun.com/app/docs/doc/820-1638/6nda01tea?l=en&a=view#abuis
    You can read more about these in
    Sun Java System Web Server 6.1 SP8 Administrator's Configuration File Reference
    http://docs.sun.com/app/docs/doc/820-1638?l=en
    and
    Sun Java System Web Server 6.1 SP8 NSAPI Programmer's Guide
    http://docs.sun.com/app/docs/doc/820-1643?l=en

  • Change console output device?

    Hi all,
    I have a laptop that I sometimes connect to a larger monitor.  I would like to be able to change my console output device so that I can connect to my larger monitor on the fly and have my console output switch over-- basically I'm looking for xrandr for the console (xrandr does the job just fine in X11).
    If I initially boot up with my laptop screen closed and my monitor connected, the console output goes to my monitor as desired.  But I would like to be able to switch output devices on the fly, rather than having to reboot to switch console output between my monitor and laptop screen.  Thanks for any help

    just found your post...
    I ask the same here http://bbs.archlinux.org/viewtopic.php?id=68589 without an answer yet, maybe you want to suscribe to mine as i do here in yours

  • Slow console output in new JDEVELOPER

    Hi,
    I have really trivial problem with new versions of JDEVELOPER (e.g. 9.0.3.1035 or
    9.0.3.1 built 1107) - slow console output.
    This OutputTest.java runs approx. 30 seconds !!
    There is no such a problem with e.g. JDEVELOPER 9.0.3.988 Preview. It takes only 0.2 second.
    Is there any workaround ? Can you help me to solve the problem?
    Thanks,
    Fero
    public class OutputTest {
    public static void main(String[] args) {
    for (int i = 0; i &lt; 1000; i++) {
    System.out.println("Very slow output" + i);

    This issue has been fixed for a later release. I don't know of any work around for you, except not writing so much to System.out and System.err.
    -Liz

  • How to set echo of console output  as ' * ' ?

    I've made a bank application in java using console input/output and when the password is typed,it echo the same word as typed.
    So how can i change the echo of console output specially when asking for password ?

    Thankue very much.
    But do me a favour i've jdk 1.5 installed in my system.
    I don't have java.io.Console class file, so will you please send me only that class file or give me link from where i can get that.
    My email address is -
    [email protected]

  • Console output on Solaris 7 and Solaris 8

    Hi All...
    It seems to me strange and impossible, but...
    I load 32-bit driver : add_drv -m '* 0600 root root' <driver_name> on Solaris 7 and 8.
    Both systems are 32-bit. The same source, the same define flags ( I use -D_KERNEL -DSUNDDI ).
    On 8 I can see my driver's console output, on 7 - no way!
    I produce console output using function cmn_err(CE_NOTE, format ...);
    One interesting thing else: after my driver has come in kernel refuses to attach it, so the driver remains unattached. After rem_drv I checked dmesg output, there I saw this :
    NOTICE: <driver name>: 64-bit driver module not found
    What could it be?? Any suggestions are welcome
    Thank you in advance
    Andrew

    Sorry, computer was booted with 64-bits kernel.
    Andrew

  • Console output - way too much info...

    when i debug my application i get loads of the following statements in the console output..
    [SWF] /blah/blah/blah.swf/[[DYNAMIC]]/1 - 172 bytes after decompression
    [SWF] /blah/blah/blah.swf/[[DYNAMIC]]/1 - 121 bytes after decompression
    [SWF] /blah/blah/blah.swf/[[DYNAMIC]]/1 - 172 bytes after decompression
    [SWF] /blah/blah/blah.swf/[[DYNAMIC]]/1 - 121 bytes after decompression
    I am using the flash builder beta 2 plug in with Zend Studio 7 and I have got swfs embedded in mx:image tags.
    Maybe it is an issue with Zend Studio and what it displays in the console...  Maybe it is a setting I don't know about in Flash Builder or it could be the embedded swfs... but if anyone can help i would really appreciate it..
    at the moment there are so many messages it is hard for me to locate my trace statements. blessings..

    still looking for an answer if anyone can help..?

  • Powershell script Information output in column instead of rows

    Dear All,
    I am required powershell script Information output  in column instead of rows.
    $usr= get-aduser -filter * | select sAMAccountName,homeDrive,TerminalServicesProfilePath,homeDirectory,physicalDeliveryOfficeName,userAccountControl,displayName,l,mail, profilepath
    $myarray = @()
    Foreach($usr1 in $usr)
    $userDN = (Get-ADUser $usr1.samaccountname).distinguishedName
    $userInfo = [ADSI]"LDAP://$userDN" | select sAMAccountName,homeDrive,TerminalServicesProfilePath,homeDirectory,physicalDeliveryOfficeName,userAccountControl,displayName,l,mail, profilepath
    $ts=$userInfo.TerminalServicesProfilePath
    $sn=$userInfo.samaccountname
    $hm=$userinfo.homeDrive
    $hd=$userinfo.homeDirectory
    $pd=$userinfo.physicalDeliveryOfficeName
    $ua=$userinfo.userAccountControl
    $dp=$userinfo.displayName
    $ll=$userinfo.l
    $ml=$userinfo.mail
    $pp=$userinfo.profilepath
    $myarray += New-Object psobject -Property @{
        Sam = $userInfo.samaccountname
        TerminalServicesProfilePath = $userInfo.TerminalServicesProfilePath
      homeDrive = $userinfo.homeDrive
        homeDirectory=$userinfo.homeDirectory
        physicalDeliveryOfficeName=$userinfo.physicalDeliveryOfficeName
        userAccountControl=$userinfo.userAccountControl
        displayName=$userinfo.displayName
         l=$userinfo.l
         mail=$userinfo.mail
         profilepath=$userinfo.profilepath
    $myarray |fl
    $myarray | Out-File "c:\final.txt"

    Hey this is such a sweet small script compared to everything else out there and I guess you can edit it to return any value you wish. One LARGE problem however: the TerminalServicesProfilePath comes back empty on all accounts regardless of whether the field
    is populated or not. This is basically because this setting is not stored in an Active Directory attribute but Terminal Services information is stored in the userParameters schema attribute as a BLOB.
    I got this script:
    $Users = ([ADSISearcher]"(&(objectCategory=person)(objectClass=user))").findall() | select path
    foreach ($user in $users) {
    $userSearch = [adsi]"$($user.path)"
    # get logon name
    $userSearch.psbase.InvokeGet(“SamAccountName”)
    # Profile Attributes
    $userSearch.psbase.InvokeGet("ProfilePath")
    # Remote Desktop Services Attributes
    $userSearch.psbase.InvokeGet("TerminalServicesProfilePath")
    which returns the value but the output is terribly unformatted. If we could integrate the two to ensure that it is correctly formatted, AND returns the TSProfile that would be awesome!
    Can anyone help me do that?
    Life is dangerous, no one has ever survived. So enjoy!
    Please do not tag an unrelated quesiton onto the end of an old and answered question.  Please read the forum guidelines before posting.
    We do not do custom scripts on demand.
    ¯\_(ツ)_/¯

Maybe you are looking for