Is it possible to pipe multiple inputs into one program? [closed] - c

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a C program that takes in 2 separate inputs through the read(0,buffer,size(buffer)) function.
They take two different inputs. Is it possible, through bash command only, to pipe two pytho -c or perl -e scripts into the C program? Or do I have to change its source code? Thanks in advance

You can use a command group
{
echo "First command"
echo "Second command"
} | nl
Or on one line for your interactive editing convenience:
{ echo "First"; echo "Second"; } | nl

Related

bash array from string keeping only content between delimiters [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm trying to create a bash script that uses info pulled from Wikipedia via curl to help sort my music collection. I've gotten it to reliably return the information I want, but because of Wikipedia's formatting, there is sometimes information I want to discard. It is also not always formatted consistently; sometimes it is on multiple lines, and sometimes only one, but the information I want is consistently delimited between "[[" and "]]". I want to keep only the text between [[ and ]] and ignore the rest. All of the solutions I've found so far use sed and rely on consistent formatting. Basically what I want to do is take a long string formatted:
{{[[abcd]]efgh[[hijk]]lmno
[[pqrs]]
[[tuvw]]yz}}
and create an array with the values
abcd
hijk
pqrs
tuvw
With GNU grep and a Perl-compatible regular expression (PCRE):
grep -Po '(?<=\[\[).*?(?=]])' file
Output:
abcd
hijk
pqrs
tuvw

How to test a C program with multiple inputs? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have Linux Ubuntu, and I want to test my program, for which someone gave me .txt file of multiple inputs. Now I want to run this program with inputs written in the .txt file. Theres a lot of inputs so I dont want to input them by hand. Is there some command in Linux Terminal to run a C with inputs written in a file?
thank you for your answers
I think you are suffering from the all too common misunderstanding that "standard input" == "a keyboard". Stop thinking that. If you've already written a program that reads from stdin, all you need to do is associate your text file with stdin. In the shell, you do that with a redirection operator:
./a.out < input.txt
If you have multiple inputs, you can easily invoke your program on each individually:
for file in *.txt; do
echo "Running on input: $file"
./a.out < "$file"
done
or you can run your program once on all the inputs:
cat *.txt | ./a.out
There are many, many ways to do what you want, and a lot of flexibility to do different things. You'll probably want to compare the output of your program with the expected output and then you're on your way to writing a full-fledged test suite. For example:
if ! ./a.out < input.txt | cmp expected-output -; then
echo "TEST FAILED" >&2
exit 1
fi

Linux script in C get file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have own script in C for linux, it is working with string loaded from file. I compiled on server gcc -pthread -o pipeline pipeline.c. It is working. Now I am running this script any like this ./pipeline UPPERCASE LOWERCASE < my_file.txt. I can read all arguments but I dont know how to read file name behind < in this script. It is possible, or how is it working?
The contents of that file will show up on your process's standard input (stdin). You don't get the name of the file, as the same interface will be used in situations where there's no filename, such as when the output of another process is piped to yours (doSomething | pipeline UPPERCASE LOWERCASE), or when the user's terminal is used for input by default.

string manipulation in AWK or in C [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a problem, I have a file with some number delimited by "". For example "125" etc.
An example of the file is:
10.0.0.0 11.0.0.0 "1200"
10.0.0.1 11.0.0.0.1 "200"
11.0.0.1 11.0.0.2 "320"
I use AWK for take the data but my problem is that I have to take only the integer value of the third column without "" because after I need to have some calculation with this numbers.
The solution is good also in C language.
Someone can help me?
Thanks
In awk, you'll have to strip off the quotes manually
$ echo '"2134"' | awk '{gsub(/(^")|("$)/,"",$1); print $1+2}'
2136
Obviously, this is not a C answer.

How to get similar functionality of Expect in a C program [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have the below expect script
#!/usr/bin/expect
set timeout 60
set user [lindex $argv 0]
set password [lindex $argv 1]
set command [lindex $argv 2]
spawn su $user
expect "Password:"
send "$password\r";
send "$command\r";
send "exit\r";
interact
How do i do the similar operations in C?
AFAIK the header expect.h provides similar functionality but i am kind of lost while using it
Any help is appreciated
If you are not locked on expect, i believe the easiest way to handle the execution of another process is via forkpty.
It allows you executing a process and control its input/output via a file descriptor.
Here is just an example i googled for.

Resources