Connecting Tech Pros Worldwide Help | Site Map

printf() with control character

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 15th, 2006, 09:55 AM
Sebastian Araya
Guest
 
Posts: n/a
Default printf() with control character

Hello,

I'm trying to write a rotational symbol in a CLI process, to report
activity to the user console, using printf( "%s\b", symbol ); but I see
the control character (\b) is been printed out instead of backspacing.

Is there any work around ?

Thanks in advance,

Sebastián.


  #2  
Old May 15th, 2006, 12:05 PM
Tim Van Wassenhove
Guest
 
Posts: n/a
Default Re: printf() with control character

On 2006-05-15, Sebastian Araya <numisys@gmail.com> wrote:[color=blue]
> Hello,
>
> I'm trying to write a rotational symbol in a CLI process, to report
> activity to the user console, using printf( "%s\b", symbol ); but I see
> the control character (\b) is been printed out instead of backspacing.
>
> Is there any work around ?[/color]

Tried "%s\\b" or '%s\\b' already?

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
  #3  
Old May 16th, 2006, 10:45 AM
numisys
Guest
 
Posts: n/a
Default Re: printf() with control character

Hello,

and thanks for your answer.

Yes, I tried it, but it didn't work... perhaps I need to use NCurses
(http://www.zend.com/pecl/tutorials/ncurses.php) ??

Best,

Sebastian

  #4  
Old May 16th, 2006, 11:05 AM
Rik
Guest
 
Posts: n/a
Default Re: printf() with control character

Tim Van Wassenhove wrote:[color=blue]
> On 2006-05-15, Sebastian Araya <numisys@gmail.com> wrote:[color=green]
>> Hello,
>>
>> I'm trying to write a rotational symbol in a CLI process, to report
>> activity to the user console, using printf( "%s\b", symbol ); but I
>> see the control character (\b) is been printed out instead of
>> backspacing.
>>
>> Is there any work around ?[/color][/color]

What about:
printf( "%s%c", symbol,8);

%c:
c - the argument is treated as an integer, and presented as the character
with that ASCII value

Then again, I know nothing about CLI.

Grtz,
--
Rik Wasmus


  #5  
Old May 16th, 2006, 11:25 AM
numisys
Guest
 
Posts: n/a
Default Re: printf() with control character

Hello,

I figured out with ANSI terminal control codes; here is a little
example:

<?

$sym = "|/-\\";

while( True )
for( $i = 0; $i!= 4; $i++ )
{
printf( "%s\x1b[D", substr( $sym, $i, 1 ) );
sleep(.25);
}

?>

I tested in a Gentoo 2006.0 using a SSH terminal under Windows
(PuTTy).

Best,

Sebastian

  #6  
Old May 16th, 2006, 11:35 AM
numisys
Guest
 
Posts: n/a
Default Re: printf() with control character

Hello Tim,

thanks again for your answer.

I think that, in PHP-CLI (console) environment, the screen is treated
as a common file, and every character output is send in a raw mode...
like if you use PHP under web development (where every output byte is
send through the net).

So, seeing Stefan Walk ProgressBar
(http://pear.php.net/package/Console_ProgressBar) I realized that using
ANSI terminal chars' control, you change the console behavior, so it
apparently deletes a char and writes a new one.

Best,

Sebastian

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.