import java.lang.Runtime;
public class VLCPlayer {
/**
* Creates a new instance of <code>VLCPlayer</code>.
*/
public VLCPlayer() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try {
Runtime.getRuntime().exec("http://localhost:6060/VideoLAN/VLC/vlc.exe");
//following line executed successfully
// Runtime.getRuntime().exec("c:/VideoLAN/VLC/vlc.exe");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
shows
java.io.IOException: CreateProcess: http:\localhost:6060\VideoLAN\VLC\vlc.exe error=2
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
at java.lang.ProcessImpl.start(ProcessImpl.java:30)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
at java.lang.Runtime.exec(Runtime.java:591)
at java.lang.Runtime.exec(Runtime.java:429)
at java.lang.Runtime.exec(Runtime.java:326)
at VLCPlayer.main(VLCPlayer.java:24)
how can i execute this program without runtime errors
2 replies to this topic
#1
Posted 21 January 2011 - 04:18 PM
|
|
|
#2
Posted 21 January 2011 - 05:09 PM
Why are you trying to execute a program over the http protocol? You can't do that.
#3
Posted 22 January 2011 - 03:32 AM
If you want to start the vlc player at a server from a client. I think it's easiest to have this runtime execute at the server and it just does: c:\program files\vlc\vlc.exe
You put this in a method at the server and then all you need to do is invoke it from the client.
You can either look up about RMI (remote method invocation: Writing an RMI Server (The Java™ Tutorials > RMI) + Creating a Client Program (The Java™ Tutorials > RMI))
Or else create a simple serversocket to which the client connects, and then the client sends strings. Dependant what these strings are the server can do some stuff. See the Strings you send as commandos you send.
Creating a client/server is fairly simple in Java
And at the client part:
A few notes:
You put this in a method at the server and then all you need to do is invoke it from the client.
You can either look up about RMI (remote method invocation: Writing an RMI Server (The Java™ Tutorials > RMI) + Creating a Client Program (The Java™ Tutorials > RMI))
Or else create a simple serversocket to which the client connects, and then the client sends strings. Dependant what these strings are the server can do some stuff. See the Strings you send as commandos you send.
Creating a client/server is fairly simple in Java
ServerSocket server = new ServerSocket(8081);
while(running){
Socket client = server.accept();
BufferedReader input = client.getInputStream();
String command = input.nextLine();
if(command.equals("Execute VLC"){
Runtime.getRuntime().exec("c:\program files\vlc\vlc.exe");
}
client.close();
}
And at the client part:
Socket connection = new Socket("127.0.0.1", 8081);
PrintWriter out = new PrintWriter(connection .getOutputStream(), true);
out.println("Execute VLC");
out.close();
connection.close;
A few notes:
- I skipped a bunch of try catches for readability.
- This is not the best server, because it won't serve any client until the previous one is finished. (You normally start a new Thread to handle each client)
- I didn't test this code, neither did i type it in an IDE. It could contain some (minor) errors.
- 127.0.0.1 should be localhost. 8081 is the port used, it must be free.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









