linux暂停报错
代码如下:import os
os.system('pause')
windows系统正常,能暂停
linux下报错:
sh: pause: not found
请问一下,在linux这代码应该怎么改,谢谢各位大神 https://wenku.baidu.com/view/808db838c6da50e2524de518964bcf84b8d52d53.html
https://blog.csdn.net/u012759006/article/details/84819894
因为在Linux的shell里pause不是一条命令,所以你这么写肯定是不对的
有帮助的话给个最佳答案谢了!!!{:10_254:} $ ls
pause.c
$ cat pause.c
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <termios.h>
int main(void) {
{
struct termios termios;
ioctl(STDIN_FILENO, TCGETS, &termios);
termios.c_lflag &= ~(ICANON | ECHO);
ioctl(STDIN_FILENO, TCSETS, &termios);
}
printf("Press any key to continue...");
getchar();
{
struct termios termios;
ioctl(STDIN_FILENO, TCGETS, &termios);
termios.c_lflag |= ICANON | ECHO;
ioctl(STDIN_FILENO, TCSETS, &termios);
}
putchar('\n');
return 0;
}
$ gcc -Wall -O3 -o pause pause.c $(pkg-config --cflags --libs ncurses)
$ ls
pausepause.c
$ ./pause
Press any key to continue...
$ ./pause
Press any key to continue...
$ ./pause
Press any key to continue...
$ ./pause
Press any key to continue...
$ cp pause ~/bin
$ cd ~/tmp
$ cat main.py
#!/usr/bin/env python
#coding=utf-8
import os
print('hello world!')
os.system('pause')
print('hello world!')
$ ./main.py
hello world!
Press any key to continue...
hello world!
$ ./main.py
hello world!
Press any key to continue...
hello world!
$ ./main.py
hello world!
Press any key to continue...
hello world!
$
$
$
$ ./main.py
hello world!
Press any key to continue...
hello world!
$
奇怪,编译命令怎么没有改过来
gcc -Wall -O3 -o pause pause.c
豆嘉木 发表于 2022-5-23 10:35
因为在Linux的shell里pause不是一条命令,所以你这么写肯定是不对的
有帮助的话给个最佳答案谢了!!!{:1 ...
这是C+的处理方法,我想要的是python的。用input('按任意键继续')可以模拟暂停效果。除了这个还有其他方法吗??大佬 kerln888 发表于 2022-5-23 11:07
这是C+的处理方法,我想要的是python的。用input('按任意键继续')可以模拟暂停效果。除了这个还有其他 ...
你写一个pause命令不就可以了
管你用什么语言写,你用python写一个pause命令
你是要解决这个问题,你还要求用什么语言来解决吗?
人造人 发表于 2022-5-23 10:48
奇怪,编译命令怎么没有改过来
这是C+的处理方法吧,我想要的是python的。用input('按任意键继续')可以模拟暂停效果。除了这个还有其他方法吗??大神 kerln888 发表于 2022-5-23 11:07
这是C+的处理方法,我想要的是python的。用input('按任意键继续')可以模拟暂停效果。除了这个还有其他 ...
嗯,看错人了,抱歉
^_^ kerln888 发表于 2022-5-23 11:14
这是C+的处理方法吧,我想要的是python的。用input('按任意键继续')可以模拟暂停效果。除了这个还有其他 ...
好吧,没有看错
你写一个pause命令不就可以了
管你用什么语言写,你用python写一个pause命令
你是要解决这个问题,你还要求用什么语言来解决吗? kerln888 发表于 2022-5-23 11:07
这是C+的处理方法,我想要的是python的。用input('按任意键继续')可以模拟暂停效果。除了这个还有其他 ...
这里有python的pause包,你去下载:https://www.cnpython.com/pypi/pause
别忘了最佳答案哈哈哈 原理都一样,要学会举一反三
#!/usr/bin/env python
#coding=utf-8
import termios
import sys
tios = termios.tcgetattr(sys.stdin.fileno())
tios &= ~(termios.ICANON | termios.ECHO)
termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, tios)
print('Press any key to continue...', end = '', flush = True)
sys.stdin.read(1)
print()
tios = termios.tcgetattr(sys.stdin.fileno())
tios |= termios.ICANON | termios.ECHO
termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, tios)
#!/usr/bin/env python
#coding=utf-8
import termios
import sys
tios = termios.tcgetattr(sys.stdin.fileno())
tios &= ~(termios.ICANON | termios.ECHO)
termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, tios)
print('Press any key to continue...', end = '', flush = True)
sys.stdin.read(1)
print('', flush = True)
tios = termios.tcgetattr(sys.stdin.fileno())
tios |= termios.ICANON | termios.ECHO
termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, tios)
页:
[1]