Real-time reading of terminal output from server

2024/10/14 6:22:15

I'm trying to process images from my camera on my server and get the information after processing on my local machine in real-time. I can get necessary information as terminal outputs on my server, but I can't put this info in my python code on local machine, until my server program is running. I'm tried this code:

cmd="sshpass -p 'pass' ssh -Y user@ip -t 'process_image; bash -l'"
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1)
for line in iter(p.stdout.readline, b''):print(line)p.stdout.close()p.wait()

But it doesn't work - it looks like this code just paused my program. I tried to write output to file and than read file from local machine, but it distorts my data. What can i do to read terminal output from server in real-time?

Answer

Since the output is going to be line buffered since you use bufsize=1, then you could just do:

cmd="sshpass -p 'pass' ssh -Y user@ip -t 'process_image; bash -l'"
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1)
for line in p.stdout:print(line).....

Of course, this assumes your command is giving you the output you expect.

https://en.xdnf.cn/q/117989.html

Related Q&A

Transform map to mapPartition using pyspark

I am trying to load a tensorflow model from disk and predicting the values.Codedef get_value(row):print("**********************************************")graph = tf.Graph()rowkey = row[0]check…

Module google_auth_httplib2 not found after pip installing google-cloud How can I fix it?

I used pip to install cloud-storage, like this:$ pip install --upgrade google-cloudWhen I started my application, I got an error that said no module named google_auth_httplib2 was found. I used pip lis…

python unbinding/disable key binding after click and resume it later

Im trying to unbind/disable key once its clicked, and resume its function after 2s. But I cant figure out the code for the unbinding. The bind is on window. Heres the code that I tried so far:self.choi…

Extracting information from pandas dataframe

I have the below dataframe. I want to build a rule engine to extract the tokens where the pattern is like Eg. "UNITED STATES" .What is the best way to do it ? Is there anything like regex o…

scipy import error with pyinstaller

I am trying to build a "One File" executable for my project with pyinstaller and a .spec file. The content of the spec file is as follows:# -*- mode: python -*-block_cipher = Nonea = Analysi…

How to compare meaningful level of a set of phrase that describe same concept in NLP?

I have two terms "vehicle" and "motor vehicle". Are there any way to compare the meaningfulness level or ambiguity level of these two in NLP? The outcome should be that "motor…

TypeError: slice indices must be integers or None or have an __index__ method. How to resolve it?

if w<h:normalized_char = np.ones((h, h), dtype=uint8)start = (h-w)/2normalized_char[:, start:start+w] = charelse:normalized_char = np.ones((w, w), dtype=uint8)start = (w-h)/2normalized_char[start:st…

Keras: Understanding the number of trainable LSTM parameters

I have run a Keras LSTM demo containing the following code (after line 166):m = 1 model=Sequential() dim_in = m dim_out = m nb_units = 10model.add(LSTM(input_shape=(None, dim_in),return_sequences=True,…

Updating Labels in Tkinter with for loop

So Im trying to print items in a list dynamically on 10 tkinter Labels using a for loop. Currently I have the following code:labe11 = StringVar() list2_placer = 0 list1_placer = 1 mover = 227 for items…

Paginate results, offset and limit

If I am developing a web service for retrieving some album names of certain artist using an API, and I am asked:The service should give the possibility to paginate results. It should support ofset= and…