我需要构建一个可以执行命令行命令并发送回命令输出的服务器
例:
对于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) 这是我的代码:
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?