Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem running cmd From Java only.

 
Ravi Kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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!
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • 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
  • 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
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, just use the absolute path:


 
Ravi Kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow !
Simple but effective. Thanks very much Stefan..
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18164
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic