「C言語でwhile内のscanfで読み取った文字列をパイプでshellscriptに渡して、そちらで標準出力する」ということをやりたいのですが、実行しても文字が表示されません。ごくごく簡単なコードなだけに、どこが間違っているのかわかりません。どなたか詳しい方ご教授お願いします。
test.c
c
1#include <stdio.h> 2 int main(){ 3 char str[256]; 4 5 while(1){ 6 scanf("%s",&str); 7 printf("%s",str); 8 } 9 }
test.sh
sh
1#!/bin/bash 2 3 while read str 4 do 5 echo "$str" 6 done 7 exit
実行コマンド
./test | ./test.sh
test.c(修正後)
c
1#include <stdio.h> 2 int main(){ 3 char str[256]; 4 5 while(1){ 6 fgets(str, sizeof(str), stdin); 7 printf("%s\n",str); 8 } 9 } 10
testコマンド(C側)への標準入力はどうやって与えていますか?
コマンドラインから"hello"とか適当に打ち込んでます
回答1件
あなたの回答
tips
プレビュー