amoffat / sh

Python process launching

Home Page:https://sh.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lack of _fg option?

akerl opened this issue · comments

The switch from pbs to sh seems to have removed the _fg option. I've scanned the documentation and can't see a recommended solution for throwing commands to the foreground. I find this useful if I'm running an intense command and want to watch its output. What's the recommended fix for this?

For completeness, I'm specifically using _fg from pbs for the following:

  • make menuconfig on Linux kernels
  • tar extractions for those tarballs
  • wget for lurking the downloads of those tarballs
  • make for making those kernels

It's on the agenda to be re-implemented. sh 1.0 had a complete rewrite of the core architecture...and unfortunately _fg hasn't yet made it back into 1.0. Your best bet for now is going to be to stick with pbs, at least for the commands that require _fg. You can use sh for everything else if you wish.

Let's leave this issue open too to remind me to add it back :)

Awesome!

+1 for this being reimplemented. I was just wondering is there was an updated eta? I'm using pbs just now to have _fg support, but it would be nice to move to over to sh...

The _fg feature would be great. I'm too using pbs ans sh together just for this reason.

I'm pretty busy for the holidays, but if another contributor can get to it, I'll merge.

Could someone please tell me, where should I look (in the code) if I want to implement the feature myself?

@dufferzafar take a good look at pexpect. use it a few times, then read the source code. once you understand the source code, it will be mostly straightforward to implement in sh

do the os.spawn family of functions meet the needs of most people? i'm trying to understand the scope of _fg more. originally i was thinking _fg would work with existing options, like being able to feed input into the process via _in. if this is not necessary though, and people just want to be able to interact manually with a launched process, then the problem becomes much simpler. sh would just be an easier interface to os.spawn

While I would love to see the _fg option added for when I want to interact with the process, it would also be nice to have an option to at least print the output to the screen when running a command. It is tedious to have to use the _iter option and then print out line by line.

@noisygecko are you imagining it kind of like how a bash script currently behaves? could you elaborate on it in a new issue?

I just mean something like:

for line in sh.tar('xvf', 'stuff.tgz', _iter=True):
    print line,

being handled like this:

sh.tar('xvf', 'stuff.tgz', _print=True)

@noisygecko want to make a new issue for it? posting on this issue notifies everyone who has replied, and this request doesn't pertain to _fg

Is there a workaround to the lack of _fg that would allow executing a fullscreen tool like vi? It works out-of-the-box with the release-1.2 branch _fg... any chance to see that released?

@lelit Unfortunately development on the next release has stagnated a bit and I don't have a timeline. Your best bet would be to do what sh is doing under the hood for fg:

import os
vi_path = "/usr/bin/vi"
os.spawnv(os.P_WAIT, vi_path, [vi_path])