sim.launchExecutable does not work in true headless mode

Typically: "How do I... ", "How can I... " questions
Post Reply
mthor13
Posts: 61
Joined: 03 Jul 2017, 08:32
Contact:

sim.launchExecutable does not work in true headless mode

Post by mthor13 »

Dear Coppelia and fellow V-"REPPERS",

I have successfully recompiled V-REP in headless mode.
However, sim.launchExecutable now fails to start executables (in my case a controller written in C++). Does anyone know why this is? It seems like the rest of the LUA script is executed as expected.

Best Regards,
Mathias Thor

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: sim.launchExecutable does not work in true headless mode

Post by coppelia »

Hello Mathias,

there could be a problem with the alternate version of the VVarious::executeExternalApplication function, then one that doesn't use Qt... maybe someone can spot the problem?

Code: Select all

bool VVarious::executeExternalApplication(const std::string& file,const std::string& arguments,const std::string& switchToDirectory,int showFlag)
{
#ifdef WIN_VREP
    int sh=SW_SHOWDEFAULT;
    if (showFlag==VVARIOUS_SHOWMAXIMIZED)
        sh=SW_SHOWMAXIMIZED;
    if (showFlag==VVARIOUS_HIDE)
        sh=SW_HIDE;
    if (switchToDirectory.length()!=0)
        SetCurrentDirectoryA(switchToDirectory.c_str()); // needed because otherwise the shellExecute command might switch directories!

    std::string cmd(file);
    if (file.size()>0)
    {
        if (file[0]=='@')
            cmd.erase(cmd.begin());
    }
    return (reinterpret_cast<long long>(ShellExecuteA(nullptr,"open",cmd.c_str(),arguments.c_str(),nullptr,sh))>32);
#else // WIN_VREP
    // Check here: http://stackoverflow.com/questions/859517/osx-equivalent-of-shellexecute
#ifdef SIM_WITHOUT_QT_AT_ALL
    std::string cmd(file);
    if (file.size()>0)
    {
        if (file[0]!='@')
        {
            if (file.find('/')==std::string::npos)
                cmd=switchToDirectory+'/';
            cmd+=file.c_str();
        }
        else
        { // for system-wide commands (e.g. xdg-open)
            cmd=file.c_str();
            cmd.erase(cmd.begin());
        }
    }

    pid_t pid;
    std::vector<char*> argsp;
    std::vector<std::string> args;
    for (int i=0;i<10;i++)
        argsp.push_back(nullptr);
    std::string w;
    std::string argu(arguments);
    while (tt::extractSpaceSeparatedWord2(argu,w,true,true,false,false,false))
    {
        args.push_back(w);
        argsp[args.size()-1]=(char*)args[args.size()-1].c_str();
    }
    pid=fork();
    if (pid==0)
    {
        execl(cmd.c_str(),cmd.c_str(),argsp[0],argsp[1],argsp[2],argsp[3],argsp[4],argsp[5],argsp[6],argsp[7],argsp[8],argsp[9],(char*)0);
        exit(0);
    }
    return(true);
#else
    QString cmd;
    if (file.size()>0)
    {
        if (file[0]!='@')
        {
            if (file.find('/')==std::string::npos)
                cmd="./";
            cmd+=QString::fromLocal8Bit(file.c_str());
        }
        else
        { // for system-wide commands (e.g. xdg-open)
            cmd=QString::fromLocal8Bit(file.c_str());
            cmd.remove(0,1);
        }
    }
    QStringList strList;
    std::string args(arguments);
    std::string word;
    while (tt::extractSpaceSeparatedWord(args,word))
        strList << QString(word.c_str());
    return(QProcess::startDetached(cmd,strList,QString::fromLocal8Bit(switchToDirectory.c_str()),nullptr));
#endif
#endif // WIN_VREP
}
Cheers

mthor13
Posts: 61
Joined: 03 Jul 2017, 08:32
Contact:

Re: sim.launchExecutable does not work in true headless mode

Post by mthor13 »

I was not able to spot the problem.

However, a temporary fix is to use the following (on Linux):

Code: Select all

     os.execute("Program PATH" .. " "Program PARAMETERS" ".."&")

Post Reply