-1

I'm trying to activate a python file (placed on my desktop) from android studio:

 String command = "python /home/roye/Desktop/check.py";
 Process p = Runtime.getRuntime().exec(command );
 DataOutputStream outputStream = new DataOutputStream(p.getOutputStream());

it gives me this error:

W/System.err: java.io.IOException: Cannot run program "python": error=13, Permission denied
W/System.err:     at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050)
        at java.lang.Runtime.exec(Runtime.java:695)
W/System.err:     at java.lang.Runtime.exec(Runtime.java:525)
        at java.lang.Runtime.exec(Runtime.java:422)
        at com.example.myapplication.MainActivity$1.onClick(MainActivity.java:42)
        at android.view.View.performClick(View.java:6608)
        at android.view.View.performClickInternal(View.java:6585)
W/System.err:     at android.view.View.access$3100(View.java:785)
        at android.view.View$PerformClick.run(View.java:25919)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:201)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6810)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
W/System.err: Caused by: java.io.IOException: error=13, Permission denied
        at java.lang.UNIXProcess.forkAndExec(Native Method)
        at java.lang.UNIXProcess.<init>(UNIXProcess.java:133)
        at java.lang.ProcessImpl.start(ProcessImpl.java:132)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
        ... 15 more

I can really use some help, thank you!

roye1233
  • 110
  • 2
  • 13
  • Does this answer your question https://stackoverflow.com/questions/32735668/permission-denied-error-13-python-on-hadoop – Ali Beyit Jan 07 '20 at 12:08
  • @AliBeyit unfortunately no.. but thanks – roye1233 Jan 07 '20 at 12:19
  • From my understanding it is basically, in java program it does not allow you to call python command (security issues as python script might be malicious). There should be workaround this problem such as allowing scripts in java and stuff. Not entirely sure, goodluck. – Ali Beyit Jan 07 '20 at 12:21
  • I think the way you use is wrong, please see this answer[https://stackoverflow.com/a/8189603/5705408] – Lenoarod Jan 07 '20 at 12:23
  • @Lenoarod Do you mean using kivi? I'm not entirely sure it will be edjusdet properly... and I rather start it all from the beginning... but thank you! – roye1233 Jan 07 '20 at 14:39
  • @roye1233, I write a simple answer for other ways, you can pick it according to your situation – Lenoarod Jan 07 '20 at 15:01

1 Answers1

2

I think the way, you run Python in android is wrong. there are some ways you can use it.

Chaquopy

a plugin for Android Studio’s Gradle-based build system.Chaquopy enables you to freely intermix Java and Python in your app, using whichever language is best for your needs

Kivy

a cross-platform OpenGL-based user interface toolkit. You can run Kivy applications on Android, on (more or less) any device with OpenGL ES 2.0 (Android 2.2 minimum).Kivy APKs are normal Android apps that you can distribute like any other, including on stores like the Play store

Pyqtdeploy

a tool for deploying PyQt applications. It supports deployment to desktop platforms (Linux, Windows and OS X) and to mobile platforms (iOS and Android).

Termux

an Android terminal emulator and Linux environment app that works directly with no rooting or setup required. A minimal base system is installed automatically

for details, you can see this wiki chart

Lenoarod
  • 3,441
  • 14
  • 25