小编guy*_*bak的帖子

python - 执行命令并获取输出

我需要构建一个可以执行命令行命令并发送回命令输出的服务器

例:

对于command-echo hello world,服务器将返回字符串"hello world".

我试图使用subprocess.call()函数,但它返回一个数字,而不是一个字符串.我准备好了服务器,我只需要这个.

码:

type=struct.pack("B",2) #packing type
data=subprocess.call(client_data, shell=True)
length=struct.pack("H",len(data)) #packing lenght
client_soc.send(type+length+data)
Run Code Online (Sandbox Code Playgroud)

python cmd

4
推荐指数
1
解决办法
2万
查看次数

如何在struct中释放指针?

这是我的代码:

typedef struct bobTheBuilder{
    char *name;
    int fix;
    int max;
};

int main(void){

    struct bobTheBuilder bob;
    initBob(&bob);
    del(&bob);

    system("PAUSE");
    return (0);
}

void initBob(struct bobTheBuilder *currBob)
{
    char *n="bob";
    currBob->name = (char*)malloc(sizeof(char)*strlen(n));
    strcpy((*currBob).name, n);
    (*currBob).fix = 0;
    (*currBob).max = 3;
}

void del(struct bobTheBuilder *currBob)
{
    free(currBob->name);
}
Run Code Online (Sandbox Code Playgroud)

视觉工作室打断了free句子.

我该怎么办?是问题free还是malloc

c struct pointers

1
推荐指数
1
解决办法
239
查看次数

标签 统计

c ×1

cmd ×1

pointers ×1

python ×1

struct ×1