zxCoder
V2EX  ›  问与答

execvp()函数的问题

  •  
  •   zxCoder · Sep 12, 2020 · 1173 views
    This topic created in 2248 days ago, the information mentioned may be changed or developed.
    #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
    zxCoder
    OP
    Sep 12, 2020
    1
    是我对这几个函数有什么误解吗
    zxCoder
    zxCoder
    OP
    Sep 12, 2020
    2
    求解!!
    ysc3839
    ysc3839
    Sep 12, 2020
    3
    我测试没问题。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1644 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 13:13 · PVG 21:13 · LAX 05:13 · JFK 08:13
    ♥ Do have faith in what you're doing.