Reading a file name from piped command

前端 未结 3 2059
余生分开走
余生分开走 2021-01-16 09:04

So I\'m trying to get the C program to read a filename from the command line in the following format: cat (filename path) | (program name)

i can get it to read the n

3条回答
  •  爱一瞬间的悲伤
    2021-01-16 09:39

    Piping content into a process does not put the values into argv; rather, it puts the values onto that process's stdin.

    You need to check if argc is greater than 1. If it is, then argv[1] has the filename you've been given (well, the first argument to the program, anyway). If not, you need to read from stdin to get the filename.

提交回复
热议问题