2015-04-01 77 views
0

这一切的Linux而不是Windows如何使用c中的路径更改xeyes的颜色?

你好,我想知道我可以改变xeyes的颜色一样,我们可以在终端做这样

xeyes -fg蓝色 现在我想做到这一点在C程序使用路径

#include <stdio.h> 
#include <unistd.h> 
#include <sys/types.h> 

#include <string.h> 
#include <malloc.h> 

//#inlcude <windows.h> 

#define LB_SIZE 1024 

int main(int argc, char *argv[]) 
{ 
    char fullPathName[] = "/usr/bin/X11/xeyes"; 
    char *myArgv[LB_SIZE]; // an array of pointers 

    myArgv[0] = (char *) malloc(strlen(fullPathName) + 1); 
    strcpy(myArgv[0], fullPathName); 

    myArgv[1] = NULL; // last element should be a NULL pointer 

    execvp(fullPathName, myArgv); 
    exit(0); // should not be reached 
} 

如果我只需拨打的/ usr/bin中/ X11/xeyes它只是显示的眼睛

现在我想要添加的命令如/ usr/bin中/ X11/xeyes-FG,但其不工作

有什么建议吗?

回答

1

您可以添加到参数向量,就像这样:

#include <stdlib.h> 
#include <stdio.h> 
#include <unistd.h> 

#include <string.h> 
#include <malloc.h> 

#define LB_SIZE 1024 

int main(int argc, char *argv[]) 
{ 
    char fullPathName[] = "/usr/bin/X11/xeyes"; 
    char *myArgv[LB_SIZE]; // an array of pointers 
    int n = 0; 

    myArgv[0] = (char *) malloc(strlen(fullPathName) + 1); 
    strcpy(myArgv[n++], fullPathName); 
    myArgv[n++] = "-fg"; 
    myArgv[n++] = "blue"; 

    myArgv[n] = NULL; // last element should be a NULL pointer 

    execvp(fullPathName, myArgv); 
    exit(0); // should not be reached 
} 

下面是结果的图片:xeyes - blue dots

随口说说,我本来期望strace显示文件rgb.txt中被已打开,但使用-f选项看不到此选项(假设它发生在服务器中)。 “蓝色”确实在跟踪中显示出来,但只在exec调用,例如,

execve("/usr/bin/X11/xeyes", ["/usr/bin/X11/xeyes", "-fg", "blue"], [/* 62 vars */]) = 0 
+0

没有工作xeyes颜色没有改变 – tjnapster555 2015-04-02 18:17:56

+0

它工作时,我跑了这个例子 - 我可以附上截图,但这可能没有帮助。非正式的,我能看到的唯一问题是,如果在你的机器上搜索“rgb.txt”有什么不妥(这会导致命名颜色不起作用)。你可以用'strace'运行你的应用程序来检查它是否成功地打开了这个文件。 – 2015-04-02 21:20:50