zxCoder
V2EX  ›  问与答

execvp()函数的问题

  •  
  •   zxCoder · Sep 12, 2020 · 854 views
    This topic created in 2081 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
        1
    zxCoder  
    OP
       Sep 12, 2020
    是我对这几个函数有什么误解吗
    zxCoder
        2
    zxCoder  
    OP
       Sep 12, 2020
    求解!!
    ysc3839
        3
    ysc3839  
       Sep 12, 2020
    我测试没问题。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3509 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 11:15 · PVG 19:15 · LAX 04:15 · JFK 07:15
    ♥ Do have faith in what you're doing.