2016-10-13 8 views
0

私はラズベリーパイとsshに接続し、pythonファイルを実行するアプリケーションを作成しました。コマンドとPythonファイルは、私のWindows PCから接続すると魅力的に動作しますが、何らかの理由でアプリケーションが何もしません。ここでAndroid SSHは何もしません

はコードです:

import android.content.pm.PackageInstaller; 
import android.os.AsyncTask; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import java.util.Properties; 

import com.jcraft.jsch.ChannelExec; 
import com.jcraft.jsch.JSch; 
import com.jcraft.jsch.Session; 

import java.io.ByteArrayOutputStream; 
import java.util.Properties; 


public class MainActivity extends AppCompatActivity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     new AsyncTask<Integer, Void, Void>() { 
      @Override 
      protected Void doInBackground(Integer... params) { 
       try { 
        executeRemoteCommand("pi", "123456", "192.168.1.6", 22); 
       } catch (Exception e) { 
        e.printStackTrace(); 
       } 
       return null; 
      } 
     }.execute(1); 
    } 

    public static String executeRemoteCommand(String username, String password, String hostname, int port) 
      throws Exception { 
     JSch jsch = new JSch(); 
     Session session = jsch.getSession(username, hostname, port); 
     session.setPassword(password); 

     // Avoid asking for key confirmation 
     Properties prop = new Properties(); 
     prop.put("StrictHostKeyChecking", "no"); 
     session.setConfig(prop); 

     session.connect(); 

     // SSH Channel 
     ChannelExec channelssh = (ChannelExec) 
       session.openChannel("exec"); 
     ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
     channelssh.setOutputStream(baos); 

     // Execute command 
     channelssh.setCommand("cd /home/pi/Desktop | nohup python red.py"); 
     //System.out.print("cd /home/pi/Desktop | nohup python red.py"); 
     channelssh.connect(); 
     channelssh.disconnect(); 

     return baos.toString(); 
    } 
} 

これは、Android Studioの出力である:あなたが完全なパスを使用していないのはなぜ

10/13 17:22:17: Launching app 
No apk changes detected since last installation, skipping installation of D:\Android\Projects\LEDControl\app\build\outputs\apk\app-debug.apk 
$ adb shell am force-stop com.example.seth.ledcontrol 
$ adb shell am start -n "com.example.seth.ledcontrol/com.example.seth.ledcontrol.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER 
Connected to process 6987 on device samsung-gt_i9195-02de24f3 
I/InstantRun: Instant Run Runtime started. Android package is com.example.seth.ledcontrol, real application class is null. 
W/InstantRun: No instant run dex files added to classpath 
I/PersonaManager: getPersonaService() name persona_policy 
W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;) 
I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested 
W/dalvikvm: VFY: unable to resolve interface method 15423: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z 
D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 
I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode 
W/dalvikvm: VFY: unable to resolve interface method 15427: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode; 
D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 
I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations 
W/dalvikvm: VFY: unable to resolve virtual method 658: Landroid/content/res/TypedArray;.getChangingConfigurations()I 
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 
I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType 
W/dalvikvm: VFY: unable to resolve virtual method 680: Landroid/content/res/TypedArray;.getType (I)I 
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 
I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable 
W/dalvikvm: VFY: unable to resolve virtual method 621: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; 
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 
I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity 
W/dalvikvm: VFY: unable to resolve virtual method 623: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; 
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 
I/Adreno-EGL: <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: Nondeterministic_AU_msm8960_KK_2.7_RB1__release_AU() 
       OpenGL ES Shader Compiler Version: 17.01.12.SPL 
       Build Date: 03/25/14 Tue 
       Local Branch: 
       Remote Branch: quic/kk_2.7_rb1.32 
       Local Patches: NONE 
       Reconstruct Branch: NOTHING 
D/OpenGLRenderer: Enabling debug mode 0 
I/dalvikvm: Total arena pages for JIT: 11 
I/dalvikvm: Total arena pages for JIT: 12 
+0

logcatがあることを行う方法を知ってはいけないあなたのアプリ –

+0

用にフィルタリングされていないよう... –

+0

のAndroid Studioは、フィルタするオプションについては、次のものを出力するドロップダウンを持っていること。基本的には、私が指摘しようとしているのは、そこにエラーはありませんし、あなたのアプリケーションからのメッセージもありません。 –

答えて

0

cdはその

のようにパイプすることができませんプログラム?

nohup python /home/pi/Desktop/red.py 
+0

Thx!それはうまくいった!私は私のWindowsのPC端末から接続する方法です前のコマンドの原因を使用! –

+0

そのようなパイプとの接続からはうまくいかないと思います。これは正しい使い方です –

関連する問題