We help IT Professionals succeed at work.

Printing on one line

ang3lus
ang3lus asked
on
Medium Priority
341 Views
Last Modified: 2012-05-11
Hi

I calculate run time of script then depend on this time i create for loop to display progress

for example if execution time 21 seconds the script will print  this shape <> 21 times
<><><><><><><><><><><

my problem is the printing display like this
<
>
<
>
<
>
<
>
<
>
<
>
<
>
<
>
<
>
<
>
How i can avoid line breaking
$time = 9;
for ($i=1; $i -le $time; $i++) {
    $sh1= "<"
     if($i % 2 -eq 0)
     {
      $sh2 = ">"
     }
    $sh1
    $sh2
    }

Open in new window

Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks.
It solved my problem
GusGallowsSupport Escalation Engineer
CERTIFIED EXPERT

Commented:
You can also add in a sleep timer to make it pop in 1 per second and also print out a blank at the end so your prompt doesn't pop up at the end of your <><><><><>.

It would look as follows:
$time = 9;
for ($i=1; $i -le $time; $i++)
{
	$sh1= "<"
	if($i % 2 -eq 0)
	{
		$sh2 = ">"
	}
	
	start-sleep -s 1
	Write-Host -NoNewline $sh1
	Write-Host -NoNewline $sh2

} 
Write-host

Open in new window

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.