吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1199|回复: 0
收起左侧

[C&C++ 转载] 采用管道执行命令行的功能分享

[复制链接]
JerusalemSky 发表于 2021-1-5 17:30
参考博客园博客:https://www.cnblogs.com/alantu2018/p/8554281.html

int my_system(const char cmd)
{
FILE
fp;
int res;
char buf[1024];
std::string strError;

if (cmd == NULL)
{
    //printf("my_system cmd is NULL!\n");
    strError = "my_system cmd is NULL!\n";
    return -1;
}

if ((fp = _popen(cmd, "r")) == NULL)
{
    perror("popen");
    //printf("popen error: %s/n", strerror(errno));
    strError = strerror(errno);
    return -1;
}
else
{
    while (fgets(buf, sizeof(buf), fp))
    {
        //printf("%s", buf);
        strError += buf;
    }

    if ((res = _pclose(fp)) == -1)
    {
        //printf("close popen file pointer fp error!\n");
        strError = "close popen file pointer fp error!\n";

        return res;
    }
    else if (res == 0)
    {
        return res;
    }
    else
    {
        //printf("popen res is :%d\n", res);
        strError = "popen res is" + to_string((long long)res);
        return res;
    }
}

}

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-5 20:40

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表