Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Looking for example code to execute OS commands on a server

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am a newbie and have tried searching but could not really find what I am looking for.  I am sure I am doing something wrong.  I would really appreciate if anyone could help me with some pointers.  This is not homework!!
I have a weblogic server running on a remote unix host.
I need to somehow manage to execute OS commands on the above unix host without using SSH.
I am wondering if it would be possible to write some kind of servlets or REST end points which would accept OS commands and execute them when called remotely say from my desktop.

Please help.

Regards
 
Marshal
Posts: 25677
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem can be divided into two parts: First, you need some Java code which can execute OS commands on the host. And second, you need to embed this code in a servlet.

Clearly the second part of the problem is fairly trivial, so your problem is reduced to the first part.

So since the servlet issue isn't a problem, if you don't mind I will move this thread to a more general forum which isn't specific to servlets.

And I'll change the thread title accordingly too. Hopefully that should make it more likely that people will answer.
 
Saloon Keeper
Posts: 6515
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java's ProcessBuilder class can be used to execute system commands.
 
Marshal
Posts: 69806
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But don't try anything with processes until you have understood the classic article by Michael Daconta called When Runtime.exec() won't. ProessBuider makes the operation simpler, but the principles are the same.
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And whatever you do, use white listing for allowed commands and arguments. Otherwise if someone can access the servlet, they can execute any arbitrary code. That can be as nasty as "rm -rf /" (wiping your entire hard drive), or even worse.
 
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic