原帖由 fengyetang 于 2008-11-25 17:46 发表
如题,我现在要向某个程序发送一串数据,其中包括"ctrl+z"的操作,要怎么来实现呢?网上查了好久,也没有什么太好的解决办法,希望哪位大侠给予指导一下。
比如:
1232131321
先谢谢了
1 #include <signal.h> 2 #include <stdlib.h> 3 #include <stdio.h> 4 5 #define MAX_LEN 250 6 char g_buf[MAX_LEN]; 7 static void ctrl_z (int signal) 8 { 9 if (signal == SIGTSTP) { 10 printf("got ctrl + z\n"); 11 gets(g_buf); 12 } else { 13 printf("receive unresolved signal\n"); 14 } 15 } 16 17 int main() 18 { 19 if (signal(SIGTSTP, ctrl_z) == SIG_ERR) { 20 printf("can't catch SIGTSTP\n"); 21 return 0; 22 } 23 printf("register SIGTSTP success\n"); 24 while (1) { 25 pause(); 26 printf("stdin: %s\n", g_buf); 27 } 28 return 0; 29 } |
原帖由 dreamice 于 2008-11-25 21:52 发表
改进版的,接收标准输入传送的数据。可以参照改进:
1 #include
2 #include
3 #include
4
5 #define MAX_LEN 250
6 char g_buf[MAX_LEN];
7 static void ctrl_z (int signal)
8 {
...
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |