• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem running cmd From Java only.

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have installed a software in a terminal and can be invoked using the following cmd
$ tclsh myinstalledsoftware.tcl inputfile

This has Tcl/Tk dependency, so installed latest version of it in my home directory.
I have set alias for the 'tclsh' in my .bashrc file which points to Tcl/Tk installed in my directory

I can run the same cmd in the terminal with no issues.
I have issues when i try to run the cmd from JAVA.
I'm using the following code to execute



I get the following error.

Tcl initialization error:
Can't find a usable init.tcl in the following directories:
{list of dir}
/usr/share/tcl8.4/init.tcl: version conflict for package "Tcl": have 8.5.8, need exactly 8.4
version conflict for package "Tcl": have 8.5.8, need exactly 8.4
while executing
"package require -exact Tcl 8.4"
(file "/usr/share/tcl8.4/init.tcl" line 19)
invoked from within
"source /usr/share/tcl8.4/init.tcl"
("uplevel" body line 1)
invoked from within
"uplevel #0 [list source $tclfile]"
This probably means that Tcl wasn't installed properly.


Any suggestions are greatly helpful
Thank You!
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Kumar wrote:
I have set alias for the 'tclsh' in my .bashrc file which points to Tcl/Tk installed in my directory

I can run the same cmd in the terminal with no issues.
I have issues when i try to run the cmd from JAVA.
I'm using the following code to execute




Java will not look into your bashrc-file. A primitiv hack might be: Start your shell from java, to execute the command:


A lot of stuff is to be considered by exec, which you may read up here: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html? but you'r actual problem not, afaik.

Maybe you may specify your settings from java directly, doing your job without bash-involvement. I heard ProcessBuilder is the preferred solution over Runtime.getRuntime, but don't know details/arguments.
 
Ravi Kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the quick reply, Stefan.

Nothing worked
I tried,
Process p = Runtime.getRuntime ().exec ("/bin/bash -c 'tclsh myinstalledsoftware.tcl inputfile'");

I tried loading the environment variable using process builder.
I tried executing the alias cmd before the actual cmd.

I have settled down to the least problem which i found, which may not be apt here.
But here is the problem...

I have an alias in my .bashrc file.
alias tclsh='/home/ravi1/tcl/lib/tcl8.5'

So when i execute in the terminal:
$ which tclsh
alias tclsh='/home/ravi1/tcl/bin/tclsh8.5'
~/tcl/bin/tclsh8.5

But when in a script, like the following

#!/bin/bash
which tclsh

The output of the script is :
$ ./runscript
/usr/bin/tclsh

Any suggestions would help...
 
Stefan Wagner
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, just use the absolute path:


 
Ravi Kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow !
Simple but effective. Thanks very much Stefan..
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any time you're running a process indirectly, it's a good idea to use the absolute path of the command, since you don't always know with certainty what the current working directory is. Cron tasks are another case where that's good advice.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic