Linux commands from Java

前端 未结 5 1030
無奈伤痛
無奈伤痛 2020-12-18 04:00

Is it possbile to execute linux commands with java? I am trying to create a web servlet to allow ftp users to change their passwords without ssh login access. I would like t

相关标签:
5条回答
  • 2020-12-18 04:26

    The java RunTime object has exec methods to run commands in a separate process

    0 讨论(0)
  • 2020-12-18 04:32

    have a look at java.lang.Runtime

    0 讨论(0)
  • 2020-12-18 04:33

    Check out this.

    However, doing what you are talking about is way outside spec, and I wouldnt reccommend it. To get it to work you are going to either run your app server as root, or use some other mechanism to give the user the app server is running as permission to execute these privileged commands. One small screw-up somewhere and you are "owned".

    0 讨论(0)
  • 2020-12-18 04:38

    If you invoke those commands from Java, make sure to pack multiple commands to a single shell-script. This will make invocation much easier.

    0 讨论(0)
  • 2020-12-18 04:39

    Use:

    Runtime.getRuntim().exec("Command");
    

    where Command is the command string you want to execute.

    0 讨论(0)
提交回复
热议问题