后台业务代码上传文件需要执行Jfrog命令,手动执行业务代码调用jfrog能够正常上传,但是后台服务通过守护进程启动后system函数返回256,为排查问题,代码中将jfrog返回信息写入日志中,如下:

std::string strupload = "jfrog rt u --explode "+xxx.zip+ " "+xxx+" >log.txt 2>&1";

查看日志如下:

[root@CI-Fsdmdept-72-156 bin]# cat log.txt
[Error] Couldn't find home directory. Make sure your HOME environment variable is set.

解决方法:

修改上传代码

std::string strupload = " HOME=/root /root/server/bin/jfrog rt u --explode "+xxx.zip+ " "+xxx +" >log.txt 2>&1";

重新测试,查看日志返回成功

[root@CI-Fsdmdept-72-156 bin]# cat log.txt
[Info] [Thread 2] Uploading artifact: /root/server/bin/tmp/public/2B4A3577-2C84-5A47-B31E-FF68284A3262/2B4A3577-2C84-5A47-B31E-FF68284A3262.zip
{
"status": "success",
"totals": {
"success": 1,
"failure": 0
}
}

开发了一个公共库管理平台,后台业务代码上传库文件需要执行Jfrog命令,手动执行业务代码调用jfrog能够正常上传,但是后台服务通过守护进程启动后system函数返回256,为排查问题,代码中将jfrog返回信息写入日志中,如下:std::stringzipfile="/root/hikpublic/server/bin/tmp/public/"+strReleaseid+"/"+strReleaseid+".zip";std::stringunzipfile......
man system可以看到如下 返回值 说明RETURN VALUE        The value returned is -1 on error (e.g.  fork(2) failed), and the return status of the command otherwise.   This  latter  return        status  is in the for
std::system - cppreference.comhttps://en.cppreference.com/w/cpp/utility/program/system 返回值 可以使用WEXITSTATUS 解析的 Return value Implementation-defined value. Ifcomma.
http://blog.chinaunix.net/uid-24774106-id-3048281.html?page=3 遇到system调用脚本,结果 返回 256 的情况,那么如何判断脚本是否正常成功调用,即取到脚本的真正 返回值 system是个综合的操作,分解开来看就是相当于执行了 1 fork  生成一个子进程。 2 在子进程执行 execl("/bin/sh","sh","-c
Linux 下system() 函数 引发的错误 今天,一个运行了近一年的程序突然挂掉了, 问题 定位到是system() 函数 出的 问题 ,关于该 函数 的简单使用在我上篇文章做过介绍: http://my.oschina.net/renhc/blog/53580 先看一下 问题 简单封装了一下system() 函数 : int pox_system(const char *cmd_line)