-
|
Hi Cli developers, Thanks very much for an extremely useful library. I am starting to use it in anger, and it is surprisingly easy to setup and get it going. I have a question regarding "scripting" of the Cli. In UNIX one can normally do [1]: telnet 10.1.1.1 <<EOF
remotecommand 1
remotecommand 2
EOFI am also able to do this with Cli, but it seems that the commands are somewhat out of order for some reason, e.g.: ./ores.client ${log_args} client <<EOF
connect localhost 55555 test
accounts create newuser2 123 567 newuser@example.com 1
exit
EOF
ORE Studio Client REPL v0.0.4
Type 'help' for available commands, 'exit' to quit
ores-client> ores-client> ✗ Not connected to server. Use 'connect' command first
ores-client> Bye!
✓ Connected
ores-client> If I use the echo based approach: {
echo "connect localhost 55555 test"
sleep 1
echo "accounts create newuser3 123 567 newuser3@example.com 1"
sleep 1
echo "exit"
} | ./ores.client ${log_args} client
ORE Studio Client REPL v0.0.4
Type 'help' for available commands, 'exit' to quit
ores-client> ores-client> ✓ Connected
ores-client> ores-client> ✓ Account created with ID: 019a5e49-476c-70ce-9909-3887cae700e9
ores-client> Bye!Do I need to do something within my shell to be able to process the commands properly, some setting I am missing perhaps. Also, and perhaps even better, is there some functionality within cli where the user can submit a file with commands? If not, I can try to have a go in implementing it, if you could give me some pointers please. Many thanks for all your efforts. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
For giggles, I just tried the echo option without the sleep and I get the exact same result: {
echo "connect localhost 55555 test"
echo "accounts create newuser3 123 567 newuser3@example.com 1"
echo "exit"
} | ./ores.client ${log_args} client
ORE Studio Client REPL v0.0.4
Type 'help' for available commands, 'exit' to quit
ores-client> ores-client> ✗ Not connected to server. Use 'connect' command first
ores-client> Bye!
✓ Connected
ores-client> |
Beta Was this translation helpful? Give feedback.
-
|
Hi marco, In my bash, if I try: daniele@daniele-kubuntu-22:~/projects/cli/cli_repo/build/examples$ cat start_complete.sh
#!/bin/bash
./complete <<EOF
color
sub
demo
exit
EOF
I get the correct output: daniele@daniele-kubuntu-22:~/projects/cli/cli_repo/build/examples$ ./start_complete.sh
cli> color
Colors ON
cli> sub
submenu> demo
This is a sample!
submenu> exit
Closing App...
Goodbye and thanks for all the fish.
I guess you've hit a very common issue when scripting interactive Command Line Interfaces (CLIs) that wrap network operations. Your suspicion that the commands might be executed in the wrong order is likely correct, but the cause isn't the script itself; it's the asynchronous nature of the 'connect' command. It seems the issue is that the connect command is asynchronous and returns immediately after initiating the connection attempt, but before the connection is actually established and ready to process the next command. Your script then immediately executes the subsequent command, which fails because the client is not yet connected. In that case, to fix the issue, make the "connect" command synchronous (i.e. returning only when the connect succeded). BTW: if you are happy with the library, please consider supporting its development with a one-time sponsorship using the heart icon at the top of the page, or look into recurring sponsorships for premium assistance. Thank you! |
Beta Was this translation helpful? Give feedback.
-
|
Thanks very much for your reply, this makes perfect sense. I'll close the discussion. |
Beta Was this translation helpful? Give feedback.
Hi marco,
thank you for using our library.
In my bash, if I try:
I get the correct output:
I guess you've hit a very common issue when scripting interactive Command Line Interfaces (CLIs) that wrap network operations.
Your suspicion that the commands might be executed in the wrong order is likely correct, but the cause isn't the scri…