簡體   English   中英

使用系統時,printf沒有給出輸出

[英]printf is not giving output when using system

我有以下代碼(部分代碼):

snprintf(
    command,
    sizeof(command),
    "%s -o %s -n \"%s\" -st %s -et %s -a \"%s\"",
    _pcOPMTRExePath,
    _pcTempFile,
    l_acHostName,
    _pcStartTime,
    _pcEndTime,
    l_acMessage
);
printf("%s",command);
l_iRetValue = system(command);
/* Return an error if failed to copy*/
if(l_iRetValue!=0)
{
    printf("18");
    return INTERNAL_ERROR;
}

問題是系統命令運行正常。 但是我的printf沒有給出命令值。 這是內存溢出或類似的問題嗎?

可能只是stdout沒有刷新-連接到控制台時,stdout通常是行緩沖的。 嘗試之一

printf("%s\n",command);

要么

printf("%s",command);
fflush(stdout);

在printf之后,可能只是stdout沒有被刷新。 嘗試在printf之后添加fflush(stdout)

大概緩沖。 嘗試在格式字符串的末尾添加\\n

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM