标签: stdout

C stdout printf

打印数据我有一个奇怪的问题.我使用printf打印char*字符串,然后打印另一个字符串.但是,第一个字符串的一部分不会被打印,当我打印第二个字符串时,第一个字符串的缺失部分会被添加到该字符串之前.这里发生了什么?

我正在写一个简单的libpcap implimentation.这是一个示例回调函数,它将产生相同的结果.我尝试在打印后删除缓冲并添加putchar('\n'),但它没有帮助.

void ParseData(u_char* useless, const struct pcap_pkthdr* pkthdr, const u_char* packet){
   int packetLen, i;
   packetLen = pkthdr->len;
   for (i = 0; i < packetLen; i++){
      putchar(packet[i]);
   }
}
Run Code Online (Sandbox Code Playgroud)

c printf stdout

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

带有一些文本的字符串变量的链值,并在C++中将其打印到标准输出

我想做一些非常简单的事情:我的函数有字符串参数,我想将它链接到一些常量字符串,然后将结果输出到控制台,如下所示:

void test(string s){
    cout << "Parameter of this function was: " << s;
}
Run Code Online (Sandbox Code Playgroud)

在其他语言中,这样的链接有效,但在C++中,编译器不满意: error C2679: binary '<<': no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

c++ string stdout bit-shift

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

前五行stdout,bash

除了使用bash管道的前五行之外,我怎样才能切掉一切?例如:

cat file.txt | truncate 5
Run Code Online (Sandbox Code Playgroud)

只打印前五行.想法?

bash truncate stdout trim

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

命令行参数,C#和stdout

我应该在C#中编写一个命令行工具.问题是,我完全不熟悉它并且必须阅读很多东西.该工具必须接受几个参数,语法我不知道它的作用.它是这样的:

tool.exe \path\data.log /lastrun:file1.txt >file2.txt
Run Code Online (Sandbox Code Playgroud)
  1. 是/ lastrun:...有效标记?
  2. 我知道> file2.txt与输出和标准输出有关,但我几乎找不到任何关于假人的信息.它写一个文本文件吗?

该工具应该在stdout上输出数据,这意味着要再次读取并可能使用其他控制台命令进行处理.如何引用输出?

我几乎没有使用命令行工具的经验.我很感激,如果有人能给我一些聪明的话,我可以查看,链接或只是解释我在这里发生了什么.

c# console stdout

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

Bash输出到变量不起作用?

我试图将命令集的输出设置为变量但是当我使用命令替换运行它时,该命令返回一个空行

[user@host bin]$ ./MyAppRead 4
Segmentation fault (core dumped)
[user@host bin]$ BALLS=$(./MyAppRead 4)
[user@host bin]$ echo $BALLS

[user@host bin]$
Run Code Online (Sandbox Code Playgroud)

我期待将BALLS设置为"Segmentation fault(core dumped)"但它是空白的?

-编辑-

更改以反映以下建议.但仍然空白

[user@host bin]$ ./MyAppRead 4
Segmentation fault (core dumped)
[user@host bin]$ BALLS=$(./MyAppRead 4 2>&1)
[user@host bin]$ echo $BALLS

[user@host bin]$
Run Code Online (Sandbox Code Playgroud)

bash stdout

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

子进程中的stdout和stderr重定向

如果我像这样运行Bash脚本:

./script.sh 2>&1
Run Code Online (Sandbox Code Playgroud)

stderr将被重定向到stdout.

如果脚本在内部调用某个工具(例如ls)或生成一个新进程,这些子进程是否stderr也将它们重定向到stdout

unix bash stdout process stderr

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

如何直接打印数字作为字符串?

printf("%s", 0x216f6c6c6548); // "Hello!" reversed
Run Code Online (Sandbox Code Playgroud)

它应该打印"你好!" 但事实并非如此.我期望得到同样的结果:

long long ll = 0x216f6c6c6548;
printf("%s", &ll);
Run Code Online (Sandbox Code Playgroud)

要么

printf("%s", "Hello!");
Run Code Online (Sandbox Code Playgroud)

是否可以将数字打印为字符串?

UPDATE

是否可以直接打印数字作为字符串?

c string stdout

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

从python派生子进程接收连续输出不起作用

我正在尝试从以python编写的秤流式传输输出。该程序(scale.py)连续运行并每半秒打印一次原始值。

import RPi.GPIO as GPIO
import time
import sys

from hx711 import HX711

def cleanAndExit():
    print "Cleaning..."
    GPIO.cleanup()
    print "Bye!"
    sys.exit()

hx = HX711(5, 6)

hx.set_reading_format("LSB", "MSB")

hx.reset()
hx.tare()

while True:
    try:
        val = hx.get_weight(5)
        print val

        hx.power_down()
        hx.power_up()
        time.sleep(0.5)
    except (KeyboardInterrupt, SystemExit):
        cleanAndExit()
Run Code Online (Sandbox Code Playgroud)

我正在尝试通过打印一个单独的NodeJs程序(位于同一文件夹中的index.js)获取每个原始数据点print val。这是我的节点程序。

var spawn = require('child_process').spawn;
var py = spawn('python', ['scale.py']);

py.stdout.on('data', function(data){
  console.log("Data: " + data);
});

py.stderr.on('data', function(data){
  console.log("Error: " + data);
});
Run Code Online (Sandbox Code Playgroud)

当我运行时sudo node index.js,没有输出,程序将永久保存。

我的想法是print val将输出放入stdout流中,并 …

python stdout spawn child-process node.js

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

bash script stdout在运行之前创建文件

我正在创建一些脚本.我将省略cron,文件更改日志等.

脚本中出现问题的部分如下:

#! /bin/bash ls>./directoryContents.txt

如果您运行此脚本,您将找到directoryContents.txt作为ls列出的文件之一.

为什么在运行ls命令之前创建了文件directoryContents.txt?

有一种简单的方法来解决这个问题吗?

bash stdout

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

创建并打开FIFO后,fprintf()到stdout无效

当我的程序启动时,它只是创建一个fifo并将其打开,之后我只想在屏幕上输出一些信息,但是什么也没打印出来。这是我的代码片段:

void listen(const server_config_t* server_conf)
{
    // Create FIFO
    if (mkfifo(SERVER_FIFO_PATH, 0660) == -1) {
        fprintf(stdout, "server FIFO not created as it already exists. continuing...\n");
    }

    // Open FIFO (for reading)
    int fd;
    if ((fd = open(SERVER_FIFO_PATH, O_RDONLY)) == -1) {
        // fprintf(stderr, "error: could not open server FIFO\n");
        perror("FIFO");
        exit(1);
    }

    // Open dummy FIFO (for writing, prevent busy waiting)
    // TODO: find way to wait without another file descriptor?
    int fd_dummy;
    if ((fd_dummy = open(SERVER_FIFO_PATH, O_WRONLY)) == -1) …
Run Code Online (Sandbox Code Playgroud)

c printf stdout fflush

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

标签 统计

stdout ×10

bash ×4

c ×3

printf ×2

string ×2

bit-shift ×1

c# ×1

c++ ×1

child-process ×1

console ×1

fflush ×1

node.js ×1

process ×1

python ×1

spawn ×1

stderr ×1

trim ×1

truncate ×1

unix ×1