Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

why doesn't my system('cls') work?

by iKnowNothing (Scribe)
on Oct 06, 2004 at 16:48 UTC ( [id://397079]=perlquestion: print w/replies, xml ) Need Help??

iKnowNothing has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'm a bit confused over this. I am trying to clear the screen using a system call. (I am running this on a Windows 2000 machine). I tried using system('cls'), but that did not work. Well, I'll let the code speak for itself,
$Output = system('cls'); print($Output);
This does not clear the screen. The output is 65280. Does anyone know what would cause this not to work? UPDATE: after running this with the -w switch, perl informs me that it Can't spawn "cmd.exe": Invalid argument at test.pl line1.

Replies are listed 'Best First'.
Re: why doesn't my system('cls') work?
by diotalevi (Canon) on Oct 06, 2004 at 16:53 UTC

    If your cmd.exe wasn't somehow missing, you should have written that as $Output = qx( cls );. system returns something entirely different than you were expecting.

Re: why doesn't my system('cls') work?
by bibo (Pilgrim) on Oct 06, 2004 at 17:09 UTC
    Well, right off the bat, there is no program named cls.com or cls.exe out there. It's a command built into the shell, cmd.exe.

    --bibo

    UPDATE

    My point is this: system and spawn and fork and their tickish brethern will launch a new process. Those new command windows could clean their own screens with cls, but you cannot clear the screen of the currently running command window by starting a new process.

    is this helping?

      Just for the record, system 'cls'; does clear the screen on a sane Win(NT|2K|XP) installation.
      might want to check that.
      the following outupt is from win xp
      C:\WINDOWS>dir cmd.exe /s Volume in drive C has no label. Volume Serial Number is 3833-835E Directory of C:\WINDOWS\system32 08/23/2001 04:00 AM 375,808 cmd.exe 1 File(s) 375,808 bytes
      you may wany to double check your %PATH% and make sure the directory that contains your cmd.exe is in it.

      -HTH
        The poster stipulated there was no cls command... not no cmd command.
Re: why doesn't my system('cls') work?
by iKnowNothing (Scribe) on Oct 06, 2004 at 18:59 UTC
    Well I got it working now. It was an environment variable problem. Apparently I didn't have the path to cmd.exe in the path variable. Thanks for the input!
      how to have the path to let it work the system ('cls')?? i have the same problem. thx
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://397079]
Approved by kvale
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-19 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found