0

I'm trying to automate some work with an interactive program. Doing SplitsTree +g Starts the CLI interactive version of the program which I would normally then enter interactively:

EXECUTE FILE=Asexual_randomSub.nxs
UPDATE
SAVE FILE=output.network
QUIT

How can I feed these commands in? Simply copying the above 6 lines into a .sh file and executing it does not work.

3 Answers 3

2

Often, many of these commands have a non interactive mode using which you can read in commands from a source file. This would be the preferred way.

Another option is to try to use a here document or pipe the inputs into stdin.

The third way is to use something like expect and manually do the whole input business. This is flaky but sometimes the only choice.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes for this particular program there is a way to read in a command file, but for some reason it is not working very well and saving output correctly - despite them being the same commands. I think it's because the kind of file the data + commands are in is often non-standard, leading to problems. But I know interactively it works - so this is a workaround.
I'd try to debug the non interactive mode and get that to work before resorting to this workaround. It's flaky and will probably blow up in your face when you least expect it.
1

Heredoc.

#!/bin/sh

SplitsTree +g << EOF
EXECUTE
FILE=Asexual_randomSub.nxs
UPDATE
SAVE
FILE=output.network
QUIT
EOF

Comments

1

Passing the commands on via the -x parameter worked for me.

SplitsTree +g -x 'EXECUTE FILE=in.nex; UPDATE; SAVE FILE=out.nex; QUIT'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.