vertx shell, how to run custom commands?

602 views
Skip to first unread message

Buddha Shrestha

unread,
Nov 2, 2016, 3:36:34 AM11/2/16
to vert.x
Hi all, 

I wanted to run some shell commands using vertx application (eg: rm -rf, cp, pwd etc). So, to start off I tried to run top command from: https://github.com/vert-x3/vertx-examples/blob/master/shell-examples/src/main/java/io/vertx/example/shell/top/TopCommand.java

But, it didn't show any output on the console, even if I pressed ctrl-c.

Also, I tried doing pwd :

Command starwars = CommandBuilder.command("pwd").
        processHandler(process -> {
          process.write("present directory:");
          process.end();
        }).build(vertx);

    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions(
        new TelnetTermOptions().setHost("localhost").setPort(3000)
    ));
    CommandRegistry.getShared(vertx).registerCommand(starwars);
    service.start(ar -> {
      if (!ar.succeeded()) {
        ar.cause().printStackTrace();
      } else {
        System.out.println("successfully executed..");
      }
    });

The processHandler is not called here.

So, am I missing out on something? What should be the right way to execute custom shell commands?



Julien Viet

unread,
Nov 2, 2016, 4:08:18 AM11/2/16
to ve...@googlegroups.com
the commands are to be executed from the shell itself when you connect via telnet or SSH.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/e401c9df-dcf4-4468-b5bd-1ec8c5bf95ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Buddha Shrestha

unread,
Nov 2, 2016, 5:01:31 AM11/2/16
to vert.x
Thanks Julien for clearing it out, I had misunderstood its purpose.

Also, are there any alternatives to execute commandline commands like cp /* /destination, rm -rf /destination ...etc. 

I know Vertx Filesystem is an alternative for this, but it does not support wildcard inputs, causing many preprocessing to be done. 

Thanks,

Julien Viet

unread,
Nov 2, 2016, 5:03:42 AM11/2/16
to ve...@googlegroups.com
it should be supported in the vertx shell cp command I think



Buddha Shrestha

unread,
Nov 2, 2016, 5:24:26 AM11/2/16
to vert.x
Are there any examples that I could refer to? I have not been able to execute vertx shell.
That would be a great help.

Thanks,

Julien Viet

unread,
Nov 2, 2016, 5:43:03 AM11/2/16
to ve...@googlegroups.com

Buddha Shrestha

unread,
Nov 2, 2016, 7:30:14 AM11/2/16
to vert.x
Julien,
I ran the example of TopCommand, but even if I telnet locahost 3000, I donot get any response.
Plus, I want to execute commandline commands without any external triggers, within my application.

Previously, used the NuProcess :https://github.com/brettwooldridge/NuProcess
and upon search, I found that you have created your own project based on it : https://github.com/vietj/vertx-childprocess

Using NuProcess, I sometimes got exceptions that would kill my process -- which was very scary thing for me.
So, I was thinking about changing the implementation where I found VertxFileSystem and VertxShell.

So, could you please suggest what should i do? 
PS: The exceptions thrown by NuProcess that terminates the process are always when I try to do : rm -rf /destination.

Thanks,

Julien Viet

unread,
Nov 2, 2016, 8:36:33 AM11/2/16
to ve...@googlegroups.com
you can run commands programmatically : it is explained in this section http://vertx.io/docs/vertx-shell/java/#_shell_server

Reply all
Reply to author
Forward
0 new messages