Forum Thread: Java Command

Java Command

Hello, does anyone know how I would send a command like "sudo pacman -Syu" in Java.

If that doesnt make sence here is what I mean. I want to make a Java program that will with buttons or something do a system update or something else but how will I get the code to come out like an actual terminal code. So here is a diagram to help me explain.

User ----> Java program -------> user clicks button in program -------> button executes code "sudo pacman -Syu" ------> System does what code is supposed to do "System upgrades".

I want to do this so I can try to learn a ton of different package managers and make one universial package manager like how Synaptics is used on Debian based systems to find and download the packages and the user not have to touch the command line. 

Sorry about the simple spelling errors it is late where I am.

7 Responses

Java doesn't like doing System Commands.. But you can find things like by searching for "System Commands Java". Personally those look pretty gross, but I didn't go over it too well. I looked at a couple hits and nothing looked much better though. 

Well it looks like

Process p = Runtime.getRuntime().exec("ps -ef");

is the only real line of code to run the code.

It might be a bit easier to do this in a shell script or something a bit more purpose built like zenity:

Doing it in java seems less practical given you will essentially be creating a shell script :P .

if [ -x $( which pacman ) ]; then



Also java is going to cause issues if you need to pipe any output to another command ( ls | grep potato ).

Yea but currently I only know java and I might be able to use this as an end of year project.

I figured you were just making use of java's easy peasy GUI abilities..

I was going to suggest you use Python or something that still makes an *easy* GUI but interacts slightly better with system than Java. If the reason is that you only know Java, well… Point moot I guess.

Well I plan on learning more languages this summer (C++?) but yea Java is all I know.

I am not saying that is at all a bad thing.. If you become super boss at one language you can get way more done than if you're mediocre at a few.

Share Your Thoughts

  • Hot
  • Active