Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

python - How can I Invoke interactive shell with initial input as SCons Phony target?

While implementing custom SCons toolchain, I've encounter situation when I need to invoke shell as Phony target with initial input already provided, so I can continue to provide input to already invoked command.

Basically, what I want is to declare Phony target with desired behaviour:

# ...
def invoke_shell(target, source, env):
    initial_input = '...'
    # Some steps to interactive command with already provided initial_input

shell = env.Command(Alias('some-shell'), [],
    invoke_shell)
env.AlwaysBuild(shell)

What I've tried is to write the following SConstruct file to cover case without initial input:

# ...
def invoke_yosys(target, source, env):
    return 'yosys'

yosys_shell = env.Command(Alias('yosys-shell'), [],
    invoke_yosys)
env.AlwaysBuild(yosys_shell)

So when I invoke scons -Q yosys-shell I should get Yosys shell, but in general case it can be any interactive command. What I expect is that shell is invoked interactively, i.e. I can enter command and Yosys shell will interactively execute commands while providing input. But it doesn't work. It exits immediately as if stdin is mapped to /dev/null.

question from:https://stackoverflow.com/questions/65863537/how-can-i-invoke-interactive-shell-with-initial-input-as-scons-phony-target

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You don't want to use Command() as that's deferred until the tree walk, you want it to run immediately before the rest of the build right?

You'd want to detect the target on the command line and then fire off the command using Execute() or os.system()..

See here for info on grabbing the command line targets.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...