LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Switch from X to console (http://www.linuxquestions.org/questions/programming-9/switch-from-x-to-console-256800/)

wizard7423 11-19-2004 07:23 AM

Switch from X to console [solved]
 
Hi at all,

i need to know a command to switch from X to a console. I need something with the same effect of: "Ctrl+Alt+F#" (with #=1,2,....,n); but as i need to put this command into a bash script file, it must be an istruction not a sequence of keystroke.
Thanks at all in advance.
Wizard

meblost 11-19-2004 09:00 AM

If you want to stop X, you can do service dm stop, or if that is not available, init 3. I'm not sure what effect, if any it will have to put these in a script.

wizard7423 12-26-2004 07:53 AM

hi, and thanks for your answer...but i don't need to stop X server. I wish switch from x to a console (outside x) with a command, and not with the usual Ctrl+Alt+F#.

Thanks anyway.
wizard

deveraux83 12-28-2004 06:45 AM

Ctrl+Alt+F#(1-6)

some kernels/distros disable certain terminals, such as slackware and only the 6th terminal is available for use. Hope this helps

meblost 12-28-2004 09:59 AM

Quote:

Originally posted by wizard7423
I wish switch from x to a console (outside x) with a command, and not with the usual Ctrl+Alt+F#.


deveraux83 12-28-2004 10:20 AM

Quote:

Originally posted by meblost
I wish switch from x to a console (outside x) with a command, and not with the usual Ctrl+Alt+F#.
DUH! I really should stop and read carefully before blabbering my mouth!

wizard7423 12-28-2004 10:22 AM

Quote:

Originally posted by deveraux83
Ctrl+Alt+F#(1-6)

some kernels/distros disable certain terminals, such as slackware and only the 6th terminal is available for use. Hope this helps

Of course...thanks for your post. Anyway i know this feature, but i'm looking for a "command" that has the same effect of Ctrl+Alt+F# , where #=1,...,6
but that i could put that instruction into a script. (Ctrl+Alt+F# is a keystroke. I cannot put a keystroke into a bash-script)

I hope to be clear this time.
Sorry for my bad english...and thanks in advance for your replies.
wizard

wizard7423 12-28-2004 10:25 AM

Quote:

Originally posted by deveraux83
DUH! I really should stop and read carefully before blabbering my mouth!
No problems!
thanks for your time!!

wizard

Cedrik 12-28-2004 12:27 PM

Here is a little tool in c that will switch from your X session to a Linux Console :

(it take number 1 to 6 as argument, or if no argument ctrl+alt+F1 is the default)

Code:

/*
        switch_from_x.c
        compile with :
        gcc -I/usr/X11R6/include -L/usr/X11R6/lib -o switch_from_x switch_from_x.c -lX11 -lXtst
       
        usage: switch_from_x [1..6]
        emulate ctrl+alt+F1..F6
        It use F1 by default
*/


#include <X11/extensions/XTest.h>
#define XK_MISCELLANY
#define XK_XKB_KEYS
#include <X11/keysymdef.h>
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
        int i;
        KeySym keys[3];
        KeySym fkeys[] = {XK_F1, XK_F2, XK_F3, XK_F4, XK_F5, XK_F6};
       
        Display* display = XOpenDisplay( NULL );
       
        if(!display) {
                printf("Error, can't open X display\n");
                exit(EXIT_FAILURE);
        }

        keys[0]        = XK_Meta_L;
        keys[1] = XK_Control_L;
        keys[2] = XK_F1;
       
        if(argc > 1) {
                i = atoi(argv[1]);
                if(i && i < 7) { keys[2] = fkeys[i-1]; }
        }
       
        for( i = 0; i < 3; i++ ) {
                XTestFakeKeyEvent ( display, XKeysymToKeycode( display, keys[i] ),
                                                        True, CurrentTime );
    }

        if( display == NULL ) exit(EXIT_FAILURE);
        XCloseDisplay(display);
        return 0;
}


hk_linux 12-28-2004 09:17 PM

chvt n, where n is the console number

You can use this at command line for switching to consoles. But i really donno wat will happen if u call from script.

HTH

wizard7423 12-29-2004 07:56 AM

thanks at all...

my question is solved.

wizard

PBSchmidt 12-29-2004 08:08 AM

on my box, chvt needs root context, is this correct?

hk_linux 12-29-2004 08:59 AM

I have no problems executing chvt from any account. I use RedHat distros

mAineAc 12-29-2004 09:11 AM

on slackware I need root access for this. you can always add it to sudo so you don't need a password.


All times are GMT -5. The time now is 09:41 AM.