...
I,m writing a program in shell script and currently this script is calling a java program.
I have a problem to pass string variable from my shell script to the java program. I don't know on how to pass it and how the java program can call what I have pass from the shell script.
...
Well, it's as simple as putting the value of your shell variable in the call to the java program. The java program doesn't really *call* the argument(s); it accesses and maybe processes them.
Here's a plain-vanilla java program that displays the input parameters:
Code:
$
$ cat testArg.java
class testArg {
public static void main (String args[]) {
System.out.println("\nInside the java program.");
System.out.println("You passed : " + args.length + " parameters.");
for (int i=0; i<=args.length-1; i++) {
System.out.println("Parameter # " + (i+1) + "\tValue = " + args[i]);
}
}
}
$
$ java testArg ant bat cat dog eel
Inside the java program.
You passed : 5 parameters.
Parameter # 1 Value = ant
Parameter # 2 Value = bat
Parameter # 3 Value = cat
Parameter # 4 Value = dog
Parameter # 5 Value = eel
$
$
I want to pass the variable $list_file to my java program..
...
I believe "list_file" contains a list of files separated by whitespace.
Here's how you can pass it to the java program shown above:
Code:
$
$ cat test_scr.sh
file_list="file1 file2 file3 file4"
echo "In the shell script."
echo "Value of file_list = $file_list"
echo "Now passing file_list to the java program..."
java testArg $file_list
$
$ . test_scr.sh
In the shell script.
Value of file_list = file1 file2 file3 file4
Now passing file_list to the java program...
Inside the java program.
You passed : 4 parameters.
Parameter # 1 Value = file1
Parameter # 2 Value = file2
Parameter # 3 Value = file3
Parameter # 4 Value = file4
$
$
tyler_durden
____________________________________
"The things you own end up owning you."
Last edited by durden_tyler; 05-17-2009 at 10:44 AM..
Hi,
I have a variable called asOfDate in shell script.
I need to pass it as a command line argument to a java command which will be called from the same shell script.
The format of that variable is "MM/DD/YYYY"
while doing echo, it is printing correctly in the java command.
ie.... (0 Replies)
I'm a beginner and wasn't able to google my problem...
I would like to pass a string with spaces to a shell script.
my test_shell:
#!/bin/sh -vx
#######################################################
# generate_documentation (c) Ch.Affolter Nov. 2009 Version 1.0 #... (3 Replies)
I have to pass a sentence in a file, the specs are as:
cat run | sed 's/SRT/'$8'/g' | sed 's/plength/68/g' | sed 's/stcol/'$5'/g' | sed 's/encol/'$6'/g' | sed 's/brdtype/'$1'/g' | sed 's/brdtxt/'$3'/g' | sed 's/demotxt/Total '$2'/g' | sed 's/bantxt/ban_'$7'/g' | sed 's/validcodes/'$4'/g' >... (15 Replies)
Hi All,
Can anybody please help me with how can i call my java program from shell and also pass parameter along with it so that the program can interpret the value/int and update the database.
Thanks in advance
Neha (1 Reply)
My shell script generates a bunch of lines of text and passes this text as an argument to a perl script.
I'm able to do this, but for some reason newlines don't get recognized in the perl script and so the script just prints actual '\n' instead of carriage returning, otherwise everything gets... (3 Replies)
Hi,
I'm trying to test one unix shell script in dev environment. But I'm not sure how to pass the environment in my java program calling code. I'm trying to use -DconsumerEnv="DEV" but unfortunately I get 'null' while trying to print the value from java class.
System.out.println("Environment: "+... (4 Replies)
I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist.
diff=$1$2.diff
id=$2 new=new_$diff
echo "My id is $1"
echo "I want to sync for user account $id"
##awk command I am using is as below
cat $diff | awk... (2 Replies)
Hello,
I am trying to execute an SQL query from shell script.
A part of script is something like this:
fromDate=`echo $(date +"%F%T") | sed "s/-//g" | sed "s/://g"`
$ORACLE_HOME/sqlplus -s /nolog <<EOD1
connect $COSDBUID/$COSDBPWD@$COSDBSID
spool... (4 Replies)
Dear Unix gurus,
We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
I can't seem to get this right. I've tried it every way imaginable using every trick I see on stackexchange and such. No luck. So nothing major here, something like:
#!/bin/bash
SEARCH="ARG1 ARG2 '((^EXACT$)|(.*InTheMiddle*)|(^AtBeginning*))'"
java -cp /my/class/path MyClassName $SEARCH... (3 Replies)