V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
zxCoder
V2EX  ›  问与答

execvp()函数的问题

  •  
  •   zxCoder · 2020-09-12 16:48:20 +08:00 · 495 次点击
    这是一个创建于 1348 天前的主题,其中的信息可能已经有所发展或是发生改变。
    #include <cstdio>
    #include <unistd.h>
    using namespace std;
    int main(){
        char buf[80];
        getcwd(buf,sizeof(buf));
        printf("current working directory: %s\n", buf);
        chdir("/home/keane/Judge/temp");
        getcwd(buf,sizeof(buf));
        printf("current working directory: %s\n", buf);
        char *array[3];
        array[0] = "java";
        array[1] = "Main";
        array[2] = NULL;
        execvp("java", array);
        return 0;
    }
    

    输出路径显示已经切换目录过去了,而且下面也确实有 Main.class,但是我这样执行就显示错误: 找不到或无法加载主类 Main

    求解

    zxCoder
        1
    zxCoder  
    OP
       2020-09-12 17:32:44 +08:00
    是我对这几个函数有什么误解吗
    zxCoder
        2
    zxCoder  
    OP
       2020-09-12 20:10:37 +08:00
    求解!!
    ysc3839
        3
    ysc3839  
       2020-09-12 21:03:32 +08:00
    我测试没问题。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2505 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 415ms · UTC 15:13 · PVG 23:13 · LAX 08:13 · JFK 11:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.