?
Solved

Printing on one line

Posted on 2011-04-29
3
Medium Priority
?
332 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

0
Comment
Question by:ang3lus
3 Comments
 
LVL 12

Accepted Solution

by:
rlandquist earned 1000 total points
ID: 35492000
Try this:
$time = 9;
for ($i=1; $i -le $time; $i++) {
    $sh1= "<"
     if($i % 2 -eq 0)
     {
      $sh2 = ">"
     }
    Write-Host -NoNewline $sh1
    Write-Host -NoNewline $sh2
    }

Open in new window

0
 

Author Closing Comment

by:ang3lus
ID: 35492429
Thanks.
It solved my problem
0
 
LVL 12

Expert Comment

by:GusGallows
ID: 35492491
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

0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Loops Section Overview

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question