The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To execute next UNIX command after ending SFTP process. gautamc Shell Programming and Scripting 3 03-20-2008 07:49 PM
empty space in java command through unix shweta_d Shell Programming and Scripting 2 06-27-2007 05:37 PM
Plz Help : How to use write command to execute command on some other terminal Aashish UNIX for Dummies Questions & Answers 2 03-03-2006 12:25 PM
Executing UNIX command from java on NT CJ Walt UNIX for Dummies Questions & Answers 1 06-25-2003 01:39 PM
Java program calling a UNIX command QUartz Ite UNIX for Dummies Questions & Answers 2 11-15-2001 09:17 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1 (permalink)  
Old 05-12-2004
mips mips is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 11
execute command unix with java:possible or not?

hi everybody,
i have a small unix script and i want to use it with java, so how can i executte unix command with java (if it is possible): in fact i want to use some values returned by this script with java swings.
is it possible (of course everything is possible) but how can i do? thank you in advance for your help.
  #2 (permalink)  
Old 05-12-2004
norsk hedensk norsk hedensk is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2002
Location: new york
Posts: 1,025
what language is the script written in? if its written in java you can run it with java. if its written in bash you can run it with bash...am i understanding your question correctly?
  #3 (permalink)  
Old 05-13-2004
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
See http://java.sun.com/j2se/1.4.2/docs/...g/Runtime.html
  #4 (permalink)  
Old 05-13-2004
mips mips is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 11
hi,
norsk hedensk my script is in bash , for example this one:

#!/bin/bash
echo "hello"

i want to know if it s possible to run it with a program java? I think that could be
  #5 (permalink)  
Old 05-13-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
It's fairly easy to execute a command that's in your PATH, for example, ls

Code:
import java.io.InputStream;
import java.io.IOException;

public class foo
{
   public foo()
   {
       Runtime rt = Runtime.getRuntime();
       Process p = null;
       try
       {
           p = rt.exec( "ls -l" );
       }
       catch ( IOException ioe )
       {
           System.out.println( "Error executing file" );
       }
       InputStream output = p.getInputStream();
       System.out.println( output );
   }

   public static void main( String args[] )
   {
       foo f = new foo();
       System.exit( 0 );
   }
}
Scripts are a little more work, have a look here
http://www.devx.com/tips/Tip/14667
that should help.


Peace,
ZB
http://www.zazzybob.com

EDIT: My code worked for commands, not scripts. Hay ho.

Last edited by zazzybob; 05-14-2004 at 06:09 AM..
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0