Comments (15)
kitten @ launch --type=background sh -c "stdout_and_stderr=$(some_script 2>&1)
from kitty.
kitten @ launch --type=background sh -c "stdout_and_stderr=$(some_script 2>&1)
It seems I didn't describe the FR clearly. I'd like to have the stdout/stderr redirects to the tty which executes the kitten command. For instance:
Current behavior:
$ kitten @ launch --type=background echo hello world
0 <--- currently it prints the exit status zero
Expected behavior:
$ kitten @ launch --type=background echo hello world
hello world <--- I'd like to get the stdout here
from kitty.
Run
echo hello world &
from kitty.
echo hello world &
Sorry I don't quite follow. How does this help?
from kitty.
from kitty.
The echo hello world
is just a demo script used to describe the FR. Real scripts will be only available on host machine and the kitten command will run on remote machine.
from kitty.
If you had said so in the first place, it would have saved some time.
Run:
kitten @ launch --type=background sh -c "exec whatever > /tmp/output 2> /tmp/output" && kitten transfer --direction=upload /tmp/output temp-output-file && cat temp-output-file && rm temp-output-file
You will get a permission prompt from the transfer kitten, read its docs
to see how to avoid that.
from kitty.
Sorry for wasting your time. I'll do more preparation before submit FR next time :)
While the provided solution addresses certain scenarios, it falls short in cases where synchronization is necessary. I understand that additional "hacks," such as waiting for temporary result files to appear in the remote shell, can be implemented. However, wouldn't it be more straightforward to extend rc.Launch.response_from_kitty
with is_asynchronous = True
and utilize subprocess.Popen.communicate()
to wait for the output? I did some tests, and it seems working.
from kitty.
You are most welcome to send a PR to add that functionality, but note
that to be acceptable it has to:
-
Allow sending stdin from the kitten invocation as stdin to the
background process. See @ send-text for an example of how to implement
this. You can possibly make it simpler to implement by only doing it
when stdin is not a tty. -
Return the stdout, stderr and exit status in the response which the
kitten should then forward to its stdout, stderr and exit status.
from kitty.
Also note that you cannot use subprocess.communicate() as that will
block the main thread of kitty. Instead you need to run the background
process redirecting the output to unnamed temp files and in your
response read from them. There is also the question of what to do when
there is a lot of output, I dont recall if the kitten is able to read
arbitrary sized responses from kitty, you will need to test.
from kitty.
Also, in the --no-response case it should work as it does currently,
with no response.
from kitty.
Oh and just for completeness, your synchronized usecase can be
implemented like this:
kitten @ launch --no-response --type=background --allow-remote-control sh -c "echo -e 'hello\nworld\nEOF' | kitten @ send-text --stdin --match id:$KITTY_WINDOW_ID"; stty_orig=`stty -g`; stty raw -echo; python -c "import sys; [sys.exit(0) if line.rstrip() == 'EOF' else print(line, end='\r') for line in sys.stdin]"; stty "$stty_orig"
In production you should of course use something more unique than EOF to
signify end of input.
from kitty.
And because I'm on a roll, here's a version without EOF and stty
kitten @ launch --no-response --type=background --allow-remote-control sh -c "echo -e 'hello\nworld\nagain' | kitten @ send-text --stdin --match id:$KITTY_WINDOW_ID; kitten @ signal-child --match id:$KITTY_WINDOW_ID"; python -c "import sys, signal, os, tty, termios; attr=termios.tcgetattr(1); tty.setraw(1); signal.signal(signal.SIGINT, lambda *a: (termios.tcsetattr(1, termios.TCSANOW, attr), os._exit(0))); [print(line, end='\r') for line in sys.stdin]";
This should be completely robust and synchronous. It will even stream
data from your command to STDOUT, not reading everything in a batch.
Which your proposed changes to --type=background wont do.
You can make it not line buffered by replacing the python one-liner with a
proper script that reads from stdin in non-blocking mode and writes to
stdout, replacing all newlines by \n\r.
from kitty.
kitten @ launch --no-response --type=background --allow-remote-control sh -c "echo -e 'hello\nworld\nagain' | kitten @ send-text --stdin --match id:$KITTY_WINDOW_ID; kitten @ signal-child --match id:$KITTY_WINDOW_ID"; python -c "import sys, signal, os, tty, termios; attr=termios.tcgetattr(1); tty.setraw(1); signal.signal(signal.SIGINT, lambda *a: (termios.tcsetattr(1, termios.TCSANOW, attr), os._exit(0))); [print(line, end='\r') for line in sys.stdin]";
Interesting. But this doesn't work when kitten
is running inside an ssh session. Signaling ssh will directly kill the connection instead of passing it to the underlying foreground process.
from kitty.
Then use a terminator like EOF.
from kitty.
Related Issues (20)
- How to spawn a remote shell? HOT 1
- UTF-8 Character Rendering Issue
- [FeatureRequest] Add a confirm config for close window when it has a running process HOT 2
- Add option to specify a color for the scrollback indicator HOT 1
- Unexpected high CPU usage in some circumstances HOT 2
- scroll lock support HOT 7
- `kitten @ action --match` not doing the action on the matched window
- Horizontal scrolling is reversed
- Feature wish: sub-pixel font hinting / anti-aliasing HOT 1
- embedded: contains no embeddable files HOT 1
- Z-index/window stack order isssue on gnome + Arch HOT 3
- Option to add outline around text for readability with low opacity HOT 1
- MacOS --start-as=fullscreen works improperly when launched with spotlight from full-screen apps HOT 5
- detect_urls includes text from next line in the URL when link fills whole row HOT 1
- FR: Support overlay window with customized size and position parameters. HOT 9
- Unicode character picker does not work like gtk ctr+shif+u HOT 1
- feat: cheap as possible NOP remote control command to just check if that window still exists HOT 2
- selection doesn't update when scrolling via the scroll wheel. HOT 3
- Tab Bar Does Not Immediately Redraw After Keyboard Mode Change HOT 3
- List processes that are keeping a tab open when a close is requested HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kitty.