0

I want to give cmd automated input command here is my code

import subprocess
from subprocess import Popen, PIPE

p = subprocess.call("cmd",shell=True)
p = Popen('cmd', stdin=PIPE)    # NOTE: no shell=True here
p.communicate(os.linesep.join(["apktool d aalpha.apk"]))

This opens cmd for me in the project directory i.e E:\myproject. Now I have this apktool in my project directory I am trying to run it automatically providing it the apktool run command in a way that I just open my python file and it executes the apktool.

pacholik
  • 8,607
  • 9
  • 43
  • 55
Azam
  • 3
  • 5
  • 1
    Why won't you run the *apktool* directly? – pacholik Feb 03 '17 at 14:20
  • i am working on a framework to automate this apktool. i just want to know how do i parse my input from script to cmd – Azam Feb 03 '17 at 14:24
  • What input? Why won't you run the apktool directly? – pacholik Feb 03 '17 at 14:30
  • You're making this way more complex than it needs to be. In the subprocess call you're running the cmd inside a shell (shell=True) so you have a shell running inside a shell. Why? Then you're overwriting the contents of p (the results of the subprocess call) with the results of a Popen command, so the subprocess is being thrown away. pacholik is correct, just run apktool with the command arguments you want directly. – Simon Hibbs Feb 03 '17 at 14:49

1 Answers1

1

Are you looking for something like this:

import subprocess;

commandA = 'start <path\file.png>';
p = subprocess.Popen(commandA, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT);
Tenzin
  • 2,415
  • 2
  • 23
  • 36
  • i want to automate input thats it i dont knw how. can u please provide ? that i run application and it gives it input itslef? – Azam Feb 04 '17 at 17:00