Launch command on remote device via ssh

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Launch command on remote device via ssh

Postby Bertrand31 » Sun Dec 06, 2009 10:02 am

Hi everyone !

I'm trying to build an application able to remotely play music on a remote computer connected on the same Wifi network.
For the connexion and to create a "remote file browser" , I used Jsch Library, and everything works great.

But to play music, I decided to use the Runtime getRuntime().exec method like this :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.          try {
  2.                          Log.i(TAG, "play totem 1");
  3.                           String command = "totem" + " " + Directory;
  4.                           Process p2 = Runtime.getRuntime().exec(command);  
  5.                           BufferedReader in = new BufferedReader(  
  6.                           new InputStreamReader(p2.getInputStream()));  
  7.                           String line = null;  
  8.                           while ((line = in.readLine()) != null) {  
  9.                           System.out.println(line);  
  10.                           }  
  11.                         Log.i(TAG, "play totem 2");      
  12.                   } catch (IOException eee) {  
  13.                          eee.printStackTrace();  
  14.                         }                                
  15.               }
  16.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


(totem is the music player used on the remote computer, and directory is actually the name of the song the user clicked on in a ListView)

And the logcat returns me this :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. I/        ( 1363): play totem 1
  2. W/System.err( 1363): java.io.IOException: Error running exec(). Commands: [totem, test.mp3] Working Directory: null Environment: null
  3. W/System.err( 1363):    at java.lang.ProcessManager.exec(ProcessManager.java:196)
  4. W/System.err( 1363):    at java.lang.Runtime.exec(Runtime.java:225)
  5. W/System.err( 1363):    at java.lang.Runtime.exec(Runtime.java:313)
  6. W/System.err( 1363):    at java.lang.Runtime.exec(Runtime.java:246)
  7. W/System.err( 1363):    at com.android.mymusicremote.MusicFolder.onListItemClick(MusicFolder.java:332)
  8. W/System.err( 1363):    at android.app.ListActivity$2.onItemClick(ListActivity.java:312)
  9. W/System.err( 1363):    at android.widget.AdapterView.performItemClick(AdapterView.java:283)
  10. W/System.err( 1363):    at android.widget.ListView.performItemClick(ListView.java:3132)
  11. W/System.err( 1363):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:1620)
  12. W/System.err( 1363):    at android.os.Handler.handleCallback(Handler.java:587)
  13. W/System.err( 1363):    at android.os.Handler.dispatchMessage(Handler.java:92)
  14. W/System.err( 1363):    at android.os.Looper.loop(Looper.java:123)
  15. W/System.err( 1363):    at android.app.ActivityThread.main(ActivityThread.java:3948)
  16. W/System.err( 1363):    at java.lang.reflect.Method.invokeNative(Native Method)
  17. W/System.err( 1363):    at java.lang.reflect.Method.invoke(Method.java:521)
  18. W/System.err( 1363):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
  19. W/System.err( 1363):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
  20. W/System.err( 1363):    at dalvik.system.NativeStart.main(Native Method)
  21. W/System.err( 1363): Caused by: java.io.IOException: No such file or directory
  22. W/System.err( 1363):    at java.lang.ProcessManager.exec(Native Method)
  23. W/System.err( 1363):    at java.lang.ProcessManager.exec(ProcessManager.java:194)
  24. W/System.err( 1363):    ... 17 more
  25.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


Anyone has an idea on what is going on ?
Bertrand31
Freshman
Freshman
 
Posts: 5
Joined: Wed Nov 18, 2009 11:29 am

Top

Postby iqueen » Fri Dec 18, 2009 2:53 am

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. File workDir = new File("c:\\");
  3.  
  4. String [] env = null;
  5.  
  6. Process p = Runtime.getRuntime().exec(cmd, env, workDir);
  7.  
  8.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


I've tried your code, even give the workdir "/" it still reports
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. 12-17 03:05:39.037   595   595 W System.err: java.io.IOException: Error running exec(). Commands: [am,  tart, -n, com.android.browser/com.android.browser.BrowserActivity] Working Directory: / Environment: []
  3.  
  4.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

do not know how to feed the String[] env.
iqueen
Freshman
Freshman
 
Posts: 3
Joined: Tue Dec 09, 2008 6:33 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 3 guests