cls command does not work on windows #181

Closed
jstenar opened this Issue Oct 22, 2010 · 20 comments

Comments

Projects
None yet
5 participants
@jstenar
Member

jstenar commented Oct 22, 2010

Hi,

the cls command does not work on windows with the pull from the master branch.
Instead of clearing the screen I only get a garbage character output (see below, * is placeholder for garbage character that was not possible to paste into the issue)

/Jörgen

C:\python\external>ipython
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 0.11.alpha1.git -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.

In [1]: cls
*

@fperez

This comment has been minimized.

Show comment
Hide comment
@fperez

fperez Oct 22, 2010

Member

Ouch, sorry.

Can you test what

!cls

and

os.system('cls')

do? That will let us know how to go about fixing this one.

Member

fperez commented Oct 22, 2010

Ouch, sorry.

Can you test what

!cls

and

os.system('cls')

do? That will let us know how to go about fixing this one.

@jstenar

This comment has been minimized.

Show comment
Hide comment
@jstenar

jstenar Oct 22, 2010

Member

!cls shows the same problem, os.system("cls") works as expected.

/Jörgen

Member

jstenar commented Oct 22, 2010

!cls shows the same problem, os.system("cls") works as expected.

/Jörgen

@fperez

This comment has been minimized.

Show comment
Hide comment
@fperez

fperez Oct 22, 2010

Member

OK, thanks for testing. That tells me what direction to go in. Sorry about that, for now perhaps just make a personal magic that does the os.system() call (in fact, that may need to be the long-term solution).

Member

fperez commented Oct 22, 2010

OK, thanks for testing. That tells me what direction to go in. Sorry about that, for now perhaps just make a personal magic that does the os.system() call (in fact, that may need to be the long-term solution).

@fperez

This comment has been minimized.

Show comment
Hide comment
@fperez

fperez Oct 22, 2010

Member

I should also mention that if you're using the new Qt console, there Ctrl-L does a screen clear, so it could come in handy as well. But we'll need to fix the actual bug, of course :)

Member

fperez commented Oct 22, 2010

I should also mention that if you're using the new Qt console, there Ctrl-L does a screen clear, so it could come in handy as well. But we'll need to fix the actual bug, of course :)

@Phillip-M-Feldman

This comment has been minimized.

Show comment
Hide comment
@Phillip-M-Feldman

Phillip-M-Feldman Sep 20, 2011

Fernando,

Why was this issue closed without being resolved?

Phillip

Fernando,

Why was this issue closed without being resolved?

Phillip

@fperez fperez reopened this Sep 20, 2011

@fperez

This comment has been minimized.

Show comment
Hide comment
@fperez

fperez Sep 20, 2011

Member

No idea, it looks like it was accidentally closed. Probably an errant mouse click, thanks for bringing it to our attention again!

Member

fperez commented Sep 20, 2011

No idea, it looks like it was accidentally closed. Probably an errant mouse click, thanks for bringing it to our attention again!

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Oct 19, 2011

Member

I think this is because on Windows, the !command syntax defaults to ip.system_piped, which won't work for commands manipulating the terminal (as I assume cls does). @minrk, I remember you worked on this - do you remember why we default to system_piped for Windows terminals, when we use system_raw in Unix terminals?

Member

takluyver commented Oct 19, 2011

I think this is because on Windows, the !command syntax defaults to ip.system_piped, which won't work for commands manipulating the terminal (as I assume cls does). @minrk, I remember you worked on this - do you remember why we default to system_piped for Windows terminals, when we use system_raw in Unix terminals?

@minrk

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Oct 19, 2011

Member

I don't remember. The original discussion is in #297. Even from that, it's not clear why os.system isn't used on Windows.

Member

minrk commented Oct 19, 2011

I don't remember. The original discussion is in #297. Even from that, it's not clear why os.system isn't used on Windows.

@jstenar

This comment has been minimized.

Show comment
Hide comment
@jstenar

jstenar Oct 20, 2011

Member

Min RK skrev 2011-10-20 01:38:

I don't remember. The original discussion is in #297. Even from that, it's not clear why os.system isn't used on Windows.

To overcome this bug I have the following in my config and it works fine
in this case.

def magic_cls(ip, x):
import os
os.system("cls")

ip.define_magic("cls", magic_cls)

Member

jstenar commented Oct 20, 2011

Min RK skrev 2011-10-20 01:38:

I don't remember. The original discussion is in #297. Even from that, it's not clear why os.system isn't used on Windows.

To overcome this bug I have the following in my config and it works fine
in this case.

def magic_cls(ip, x):
import os
os.system("cls")

ip.define_magic("cls", magic_cls)

@minrk

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Oct 20, 2011

Member

Do you want to do a PR that does os.system for magic_cls on Windows?

Or, if we can't find a reason to use system_piped in the Terminal on Windows, we can just make Windows always use os.system. My guess is it has to do with piping through pyreadline in order to get ANSI colors to work, but what subprocesses use unix color output on Windows?

Member

minrk commented Oct 20, 2011

Do you want to do a PR that does os.system for magic_cls on Windows?

Or, if we can't find a reason to use system_piped in the Terminal on Windows, we can just make Windows always use os.system. My guess is it has to do with piping through pyreadline in order to get ANSI colors to work, but what subprocesses use unix color output on Windows?

jstenar pushed a commit to jstenar/ipython that referenced this issue Oct 20, 2011

@jstenar

This comment has been minimized.

Show comment
Hide comment
@jstenar

jstenar Oct 20, 2011

Member

Min RK skrev 2011-10-20 21:17:

Do you want to do a PR that does os.system for magic_cls on Windows?

Or, if we can't find a reason to use system_piped in the Terminal on Windows, we can just make Windows always use os.system. My guess is it has to do with piping through pyreadline in order to get ANSI colors to work, but what subprocesses use unix color output on Windows?

Ok, done in PR #912

Member

jstenar commented Oct 20, 2011

Min RK skrev 2011-10-20 21:17:

Do you want to do a PR that does os.system for magic_cls on Windows?

Or, if we can't find a reason to use system_piped in the Terminal on Windows, we can just make Windows always use os.system. My guess is it has to do with piping through pyreadline in order to get ANSI colors to work, but what subprocesses use unix color output on Windows?

Ok, done in PR #912

@Phillip-M-Feldman

This comment has been minimized.

Show comment
Hide comment
@Phillip-M-Feldman

Phillip-M-Feldman Oct 20, 2011

I put the following into my ipy_user_conf.py file, but it didn't resolve the problem:

import os

def magic_cls(ip, x):
os.system("cls")

ip.define_magic("cls", magic_cls)

I still get the symbol that stands for "female". Perhaps some radical feminist is at work here?

I put the following into my ipy_user_conf.py file, but it didn't resolve the problem:

import os

def magic_cls(ip, x):
os.system("cls")

ip.define_magic("cls", magic_cls)

I still get the symbol that stands for "female". Perhaps some radical feminist is at work here?

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Oct 20, 2011

Member

If you're using IPython 0.11 or trunk, ipy_user_conf.py is no longer used. You need to look for profile_default/ipython_config.py (and the format is different as well)

Member

takluyver commented Oct 20, 2011

If you're using IPython 0.11 or trunk, ipy_user_conf.py is no longer used. You need to look for profile_default/ipython_config.py (and the format is different as well)

@jstenar

This comment has been minimized.

Show comment
Hide comment
@jstenar

jstenar Oct 20, 2011

Member

pmfeldman skrev 2011-10-21 00:09:

I put the following into my ipy_user_conf.py file, but it didn't resolve the problem:

import os

def magic_cls(ip, x):
os.system("cls")

ip.define_magic("cls", magic_cls)

I still get the symbol that stands for "female". Perhaps some radical feminist is at work here?

If you type %magic at the prompt do you see cls in the list of available
magic commands?

Do you have automagic enabled? Otherwise you would have to write %cls

Member

jstenar commented Oct 20, 2011

pmfeldman skrev 2011-10-21 00:09:

I put the following into my ipy_user_conf.py file, but it didn't resolve the problem:

import os

def magic_cls(ip, x):
os.system("cls")

ip.define_magic("cls", magic_cls)

I still get the symbol that stands for "female". Perhaps some radical feminist is at work here?

If you type %magic at the prompt do you see cls in the list of available
magic commands?

Do you have automagic enabled? Otherwise you would have to write %cls

@Phillip-M-Feldman

This comment has been minimized.

Show comment
Hide comment
@Phillip-M-Feldman

Phillip-M-Feldman Oct 20, 2011

Ah! I'm now editing the correct configuration file, and got the following
error:

363 # Define cls "magic":
364 import os
365
366 def magic_cls(ip, x):
367     os.system("cls")
368

--> 369 define_magic("cls", magic_cls)
global define_magic = undefined
global magic_cls = <function magic_cls at 0x00FF1EF0>

NameError: name 'define_magic' is not defined

I know that define_magic is in the ip module, but If I try to import
ip, I get an error that this module cannot be found.

Phillip

On Thu, Oct 20, 2011 at 3:17 PM, Thomas <
reply@reply.github.com>wrote:

If you're using IPython 0.11 or trunk, ipy_user_conf.py is no longer
used. You need to look for profile_default/ipython_config.py (and the
format is different as well)

Reply to this email directly or view it on GitHub:
#181 (comment)

Ah! I'm now editing the correct configuration file, and got the following
error:

363 # Define cls "magic":
364 import os
365
366 def magic_cls(ip, x):
367     os.system("cls")
368

--> 369 define_magic("cls", magic_cls)
global define_magic = undefined
global magic_cls = <function magic_cls at 0x00FF1EF0>

NameError: name 'define_magic' is not defined

I know that define_magic is in the ip module, but If I try to import
ip, I get an error that this module cannot be found.

Phillip

On Thu, Oct 20, 2011 at 3:17 PM, Thomas <
reply@reply.github.com>wrote:

If you're using IPython 0.11 or trunk, ipy_user_conf.py is no longer
used. You need to look for profile_default/ipython_config.py (and the
format is different as well)

Reply to this email directly or view it on GitHub:
#181 (comment)

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Oct 20, 2011

Member

ip is a reference to the InteractiveShell object, which is instantiated
after the config file is loaded. I think you need to put it inside the
exec_lines variable, and use "ip = get_ipython()" to get a reference to it.

We do need an easier way to do this sort of thing.

Member

takluyver commented Oct 20, 2011

ip is a reference to the InteractiveShell object, which is instantiated
after the config file is loaded. I think you need to put it inside the
exec_lines variable, and use "ip = get_ipython()" to get a reference to it.

We do need an easier way to do this sort of thing.

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Oct 20, 2011

Member

I've opened #914 for an easier way to do this sort of config.

Member

takluyver commented Oct 20, 2011

I've opened #914 for an easier way to do this sort of config.

@Phillip-M-Feldman

This comment has been minimized.

Show comment
Hide comment
@Phillip-M-Feldman

Phillip-M-Feldman Oct 23, 2011

After some fiddling, I came up with something that works:

Define cls "magic":

c.TerminalIPythonApp.exec_lines= [
'import os',
'ipython= get_ipython()',
'ipython.define_magic("cls", lambda x,y: os.system("cls"))'
]

I'm unclear as to why the lambda function is receiving two arguments, but
apparently it does.

Thanks for the help!

Phillip

On Thu, Oct 20, 2011 at 4:53 PM, Thomas <
reply@reply.github.com>wrote:

I've opened #914 for an easier way to do this sort of config.

Reply to this email directly or view it on GitHub:
#181 (comment)

After some fiddling, I came up with something that works:

Define cls "magic":

c.TerminalIPythonApp.exec_lines= [
'import os',
'ipython= get_ipython()',
'ipython.define_magic("cls", lambda x,y: os.system("cls"))'
]

I'm unclear as to why the lambda function is receiving two arguments, but
apparently it does.

Thanks for the help!

Phillip

On Thu, Oct 20, 2011 at 4:53 PM, Thomas <
reply@reply.github.com>wrote:

I've opened #914 for an easier way to do this sort of config.

Reply to this email directly or view it on GitHub:
#181 (comment)

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Oct 23, 2011

Member

On 23 October 2011 21:16, pmfeldman <
reply@reply.github.com>wrote:

I'm unclear as to why the lambda function is receiving two arguments, but
apparently it does.

Magic functions always receive two arguments - the shell, and the string of
arguments the magic function was called with. There's no special way of
defining a magic function that doesn't expect any arguments.

Member

takluyver commented Oct 23, 2011

On 23 October 2011 21:16, pmfeldman <
reply@reply.github.com>wrote:

I'm unclear as to why the lambda function is receiving two arguments, but
apparently it does.

Magic functions always receive two arguments - the shell, and the string of
arguments the magic function was called with. There's no special way of
defining a magic function that doesn't expect any arguments.

@fperez

This comment has been minimized.

Show comment
Hide comment
@fperez

fperez Oct 24, 2011

Member

On Sun, Oct 23, 2011 at 1:16 PM, pmfeldman
reply@reply.github.com
wrote:

Define cls "magic":

c.TerminalIPythonApp.exec_lines= [
  'import os',
  'ipython= get_ipython()',
  'ipython.define_magic("cls", lambda x,y: os.system("cls"))'
]

I'm unclear as to why the lambda function is receiving two arguments, but
apparently it does.

Just a minor note: you can put the above in a single triple-quoted
string to save yourself some extra quotes and commas:

c.TerminalIPythonApp.exec_lines= ["""
import os
ipython= get_ipython()
ipython.define_magic("cls", lambda x,y: os.system("cls"))""",
]

And just to add to Thomas' (correct) comment: the two args are because
magics are currently methods of the shell, so the builtin ones are
defined as

def magic_foo(self, line):...

Since they are dynamically added to the instance, they must still
support the same signature.

I do have thoughts on a long-term redesign of the magic system, but
there's simply too much in-flight right now to think about that.

Cheers,

f

Member

fperez commented Oct 24, 2011

On Sun, Oct 23, 2011 at 1:16 PM, pmfeldman
reply@reply.github.com
wrote:

Define cls "magic":

c.TerminalIPythonApp.exec_lines= [
  'import os',
  'ipython= get_ipython()',
  'ipython.define_magic("cls", lambda x,y: os.system("cls"))'
]

I'm unclear as to why the lambda function is receiving two arguments, but
apparently it does.

Just a minor note: you can put the above in a single triple-quoted
string to save yourself some extra quotes and commas:

c.TerminalIPythonApp.exec_lines= ["""
import os
ipython= get_ipython()
ipython.define_magic("cls", lambda x,y: os.system("cls"))""",
]

And just to add to Thomas' (correct) comment: the two args are because
magics are currently methods of the shell, so the builtin ones are
defined as

def magic_foo(self, line):...

Since they are dynamically added to the instance, they must still
support the same signature.

I do have thoughts on a long-term redesign of the magic system, but
there's simply too much in-flight right now to think about that.

Cheers,

f

minrk added a commit to minrk/ipython that referenced this issue Nov 9, 2011

use system_raw in terminal, even on Windows
`system_raw` uses `os.system` instead of `utils.process.system`, and makes
more sense in a Terminal session.

There was discussion that it should be otherwise on Windows, but I can't
find any actual evidence for why this would be the case, and there are very
clear disadvantages to not using `os.system` (see #978 and #181).

closes gh-978

minrk pushed a commit to minrk/ipython that referenced this issue Jul 1, 2013

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

use system_raw in terminal, even on Windows
`system_raw` uses `os.system` instead of `utils.process.system`, and makes
more sense in a Terminal session.

There was discussion that it should be otherwise on Windows, but I can't
find any actual evidence for why this would be the case, and there are very
clear disadvantages to not using `os.system` (see #978 and #181).

closes gh-978
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment