K
K
ksvdon2016-09-14 00:41:54
linux
ksvdon, 2016-09-14 00:41:54

How to redirect output from process in background to variable?

I'm accessing the site using curl which is causing a CPU load. I need to log the load, but in the end I have to get a response from the site. I run curl in the background and redirect the output to a file. In the loop, I register the load and try to read the data from the file. When the data appears - everything is ok. If they do not appear for some time (according to the counter) - I also get a certain result. I want to write the output from a process in the background not to a file, but to a variable. How to do it?
Now I do
curl blabla & >$filename.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2016-09-14
@saboteur_kiev

You should not run curl in the background, but the whole script, and then you can do this:
variable=`curl blabla`
...check variable..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question