PHP exec java on IIS 7 - java

I am trying to exec a java jar file using php exec();
The command is
"C:\Program Files\Java\jdk1.5.0_15\bin\java.exe" -jar "C:\batik\batik-rasterizer.jar" -m image/png -d "C:/path/to/file/filename.png" -w 800 "C:/path/to/file/filename.svg"
When I run this command on the server using CMD.exe or Power Shell works fine but when I run it with PHP using exec() or system() or shell_exec() it will not execute returning a blank page

OK I got it figured out,
First the java jdk shouldn't be installed in the programs folder for some reason iis_iusrs doesn't have the permission to execute any files there.
Secondly the code should look like this
exec("C:\\Java\\jre6\\bin\\java.exe -jar C:\\batik\\batik-rasterizer.jar -m image/png -d "C:\\path\\to\\file\\filename.png" -w 800 "C:\\path\\to\\file\\filename.svg");

Related

Execute a .jar file using shell script

I want to execute a jar file of DOMO CLI from a shell script. The jar file itself has some functions which I want to call after I call the main jar file. The problem which I am facing is that after it executes the jar file, I am not able to pass the additional commands to execute inside that jar through a shell script. It just stops after calling jar and doesn't take further commands. Can anyone please help? Below is the code I am calling from a shell script.
java -jar XX.jar
The commands are as below which follow the above jar. So once we enter into the above jar we have to execute the below commands one after the other. I am not sure how to achieve this through a shell script.
connect -s X.domo.com -t Ysssss
upload-dataset -a -i dhdhdhdh -f /prehdfs/dev/comres/herm/data/yyyy.csv
Did you try using pipes and inputs.
When you execute above it runs it under a child shell.
You may try below format if not tried already
$ (echo "connect -s X.domo.com -t Ysssss" && cat) | java -jar XX.jar
If you can reference a file in your use case, you could put your commands in a file.
File: list_my_datasets.domo
connect -t ... -s ...
list-dataset
quit
then run the command:
java -jar domoUtil.jar -script list_my_datasets.domo > datasets
I wanted the data from it so I piped to a file (where I had to grep what I wanted), but you would omit that I believe, unless it has some output you'd want to check. I haven't tested with the upload command, but I would hope any commands substituted or added to the example work similarly.
Domo docs on scripting

How to run a script in user mode inside an executable jar that is executed as root?

I want to run the following script within a Java executable jar on the Raspberry Pi.
the script (= stream.sh):
#!/bin/sh
raspivid -fps 25 -w 640 -h 360 -vf -n -o - -t 999999 |cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/cam.sdp,rtcp-mux}' :demux=h264
the Java code:
Runtime.getRuntime().exec("sh stream.sh"));
The problem is that the jar must be run with sudo and the vlc command doesn't accept sudo. Neither the script or the Java code contain sudo but as the jar is executed as sudo, vlc still gives the error "VLC is not supposed to be run as root...".
What is the easiest way to make the script run in user mode inside the jar?
I would use su -l $LOGIN -c $CMD or sudo -u $LOGIN $CMD.
Runtime.getRuntime().exec("sudo -u myuser sh stream.sh"));
man sudoers has all the information you need.
You need to change /etc/sudoers

Specifying Play 2.0 port with "dist"

I'm creating a packaged project usingdist and am trying to modify the generated start script to run the app on port 9001.
Here is what is generated:
exec java $* -cp "`dirname $0`/lib/*" play.core.server.NettyServer `dirname $0`
Here is what I tried, which doesn't seem to work.
exec java $* -Dhttp.port=9001 -cp "`dirname $0`/lib/*" play.core.server.NettyServer `dirname $0`
Any ideas?
I've also tried specifying http.port=9001 in application.conf with no avail. It was very easy to do this in Play 1.2.X, seems a step backward.
After running play dist and then extracting the generated bundle, you can start Play 2 on a different port by running:
./start -Dhttp.port=5432
Or if you would rather edit the start script you can update it to be:
#!/usr/bin/env sh
exec java $* -Dhttp.port=5432 -cp "`dirname $0`/lib/*" play.core.server.NettyServer `dirname $0`
And then run:
./start

ArrayIndexOutOfBounds Exception on executing linux sh file

I have a program in java which takes 0'th aargument as file location like
File f = new File(args[0]);
so when i execute it using a windows batch(.bat) file it works correctly .
but when i execute the same using a linux shell file(.sh) in linux i get ArrayIndexOutOfBoundsException.
WINDOWS BATCH FILE :
#echo off
for /f %%i in ("%0") do set scriptpath=%%~dpi
set cp=%scriptpath%/../lib/*.jar;
java -classpath %cp% com.synchronizer.main.MYSynchronizer %scriptpath% "%1" "%2"
LINUX SH FILE:
export JAVA_HOME=/usr/local/java
PATH=/usr/local/java/bin:${PATH}
THE_CLASSPATH=
for i in `ls ../lib/*.jar`
do
THE_CLASSPATH=${THE_CLASSPATH}:${i}
done
java -cp ".:${THE_CLASSPATH}" \
com.synchronizer.main.MYSynchronizer
please help!
It looks like a problem in script (no arguments are passed to the Java program).
You can consider to debug the script like this: debugging scripts
Hope this helps
Your shell script is not passing any parameters:
java -cp ".:${THE_CLASSPATH}" com.synchronizer.main.MYSynchronizer
Try:
java -cp ".:${THE_CLASSPATH}" com.synchronizer.main.MYSynchronizer "$1" "$2"
As stated above, your Linux shell script is not sending any arguments to the Java program that you are trying to start.
And, adding to that, you are not showing us how you run the Linux shell script. If no argument is given on the command line when you start the shell script, no arguments can be passed to your Java application from the shell script.
If you want to see the actual command that is going to be run by your shell script, you can always put "echo" in front of a line and see what all variables are expanded to. This is a simple way to debug shell scripts.

how to launch java GUI test from linux

-java -classpath<> <classname> in the ".bat" file to launch java test from cmd windows
how to do that using perl to launch java test from linux ?
Don't use perl. For such a simple job, a simple shell script will do:
#!/bin/sh
/path/to/java -classpath foo.jar:bar.jar:. classname
Make the file executable with chmod +x filename and execute it with ./filename
A similar approach using the -jar option is possible. Additionally, you can forward any command line parameters using the special parameter #.
#!/bin/sh
/path/to/java -jar foo.jar "${#}"

Categories