Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #111310 > unrolled thread
| Started by | "Veek. M" <vek.m1234@gmail.com> |
|---|---|
| First post | 2016-07-12 08:50 +0530 |
| Last post | 2016-07-12 18:42 -0700 |
| Articles | 6 — 4 participants |
Back to article view | Back to comp.lang.python
subprocess: xterm -c cat, need to send data to cat and have it displayed in the xterm window "Veek. M" <vek.m1234@gmail.com> - 2016-07-12 08:50 +0530
Re: subprocess: xterm -c cat, need to send data to cat and have it displayed in the xterm window Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-07-12 16:27 +1000
Re: subprocess: xterm -c cat, need to send data to cat and have it displayed in the xterm window Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-07-12 16:28 +1000
Re: subprocess: xterm -c cat, need to send data to cat and have it displayed in the xterm window Random832 <random832@fastmail.com> - 2016-07-12 09:39 -0400
Re: subprocess: xterm -c cat, need to send data to cat and have it displayed in the xterm window "Veek. M" <vek.m1234@gmail.com> - 2016-07-12 19:43 +0530
Re: subprocess: xterm -c cat, need to send data to cat and have it displayed in the xterm window Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-12 18:42 -0700
| From | "Veek. M" <vek.m1234@gmail.com> |
|---|---|
| Date | 2016-07-12 08:50 +0530 |
| Subject | subprocess: xterm -c cat, need to send data to cat and have it displayed in the xterm window |
| Message-ID | <nm1nln$sku$1@dont-email.me> |
Script grabs some image data and runs imagemagick on it to extract some
chinese. Then tesseract OCR to get the actual unicode.
I then need to get it translated which also works and then display in
XTerm using cat.
I could cat << named_pipe but I was wondering if this was the only way?
Could I juggle fd's instead?
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys, time
import shlex
import codecs, subprocess
import goslate
from textblob.blob import TextBlob
def cmd_exec(cmd, wait=True, shell=True):
print cmd
cmd_line = shlex.split(cmd)
retobj = subprocess.Popen(cmd_line, shell, cwd='/tmp',
stdin=subprocess.PIPE)
if wait:
retobj.wait()
return retobj
def get_text_and_process(skip=False):
if skip: return
cmd_exec('import /tmp/x.png')
cmd_exec('convert /tmp/x.png -resize 200% /tmp/x.resize.png')
cmd_exec('tesseract /tmp/x.resize.png /tmp/tao -l chi_sim')
get_text_and_process(skip=True)
fh = codecs.open('/tmp/tao.txt', encoding='utf-8')
fd = cmd_exec('xterm -en utf-8 -geometry 50x20+0+0 -e /bin/bash -c "cat
-"', shell=False, wait=False)
fd.communicate('test\n') #how do i communicate with cat and not xterm
sys.exit() #I EXIT HERE
#This stuff doesn't run (but works) - sys.exit above
for line in fh.readlines():
try:
print >>fd.stdout, line.encode('utf-8')
blob = TextBlob(line)
print >>fd.stdout, blob.detect_language()
print >>fd.stdin, blob.translate(to='en')
except UnicodeDecodeError, TranslatorError:
pass
fh.close()
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2016-07-12 16:27 +1000 |
| Message-ID | <57848dba$0$11093$c3e8da3@news.astraweb.com> |
| In reply to | #111310 |
On Tuesday 12 July 2016 13:20, Veek. M wrote: > Script grabs some image data and runs imagemagick on it to extract some > chinese. Then tesseract OCR to get the actual unicode. > > I then need to get it translated which also works and then display in > XTerm using cat. Why not just print it? Why do you have to use cat? That sounds like "Useless use of cat" to me: http://porkmail.org/era/unix/award.htmlhttp://porkmail.org/era/unix/award.html -- Steve
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2016-07-12 16:28 +1000 |
| Message-ID | <57848e26$0$11093$c3e8da3@news.astraweb.com> |
| In reply to | #111320 |
On Tuesday 12 July 2016 16:27, Steven D'Aprano wrote: > On Tuesday 12 July 2016 13:20, Veek. M wrote: > >> Script grabs some image data and runs imagemagick on it to extract some >> chinese. Then tesseract OCR to get the actual unicode. >> >> I then need to get it translated which also works and then display in >> XTerm using cat. > > Why not just print it? Why do you have to use cat? That sounds like "Useless > use of cat" to me: > > http://porkmail.org/era/unix/award.htmlhttp://porkmail.org/era/unix/award.html > Oopsm, accidentally doubled the URL. http://porkmail.org/era/unix/award.html -- Steve
[toc] | [prev] | [next] | [standalone]
| From | Random832 <random832@fastmail.com> |
|---|---|
| Date | 2016-07-12 09:39 -0400 |
| Message-ID | <mailman.17.1468330785.21009.python-list@python.org> |
| In reply to | #111320 |
On Tue, Jul 12, 2016, at 02:27, Steven D'Aprano wrote: > On Tuesday 12 July 2016 13:20, Veek. M wrote: > > I then need to get it translated which also works and then display in > > XTerm using cat. > > Why not just print it? Why do you have to use cat? Well, displaying something in a new xterm (i.e. not one that already exists and is your controlling terminal) without a process to run "in" the terminal is rather esoteric and isn't portable to terminals other than xterm.
[toc] | [prev] | [next] | [standalone]
| From | "Veek. M" <vek.m1234@gmail.com> |
|---|---|
| Date | 2016-07-12 19:43 +0530 |
| Message-ID | <nm2tuc$eua$1@dont-email.me> |
| In reply to | #111320 |
Steven D'Aprano wrote: > On Tuesday 12 July 2016 13:20, Veek. M wrote: > >> Script grabs some image data and runs imagemagick on it to extract >> some chinese. Then tesseract OCR to get the actual unicode. >> >> I then need to get it translated which also works and then display in >> XTerm using cat. > > Why not just print it? Why do you have to use cat? That sounds like > "Useless use of cat" to me: > > http://porkmail.org/era/unix/award.htmlhttp://porkmail.org/era/unix/award.html > Yeah, i changed that to 'tail -f' - works much better with tempfile.
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D’Oliveiro <lawrencedo99@gmail.com> |
|---|---|
| Date | 2016-07-12 18:42 -0700 |
| Message-ID | <f3e63fe4-ff06-4dfa-bddb-296b4bf33b16@googlegroups.com> |
| In reply to | #111310 |
On Tuesday, July 12, 2016 at 3:20:35 PM UTC+12, Veek. M wrote: > I then need to get it translated which also works and then display in > XTerm using cat. <http://catb.org/jargon/html/U/UUOC.html>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web