开发者

raw_input in python variable to cmd

开发者 https://www.devze.com 2023-03-28 19:12 出处:网络
How can I take this code, and take the raw_input and add \"ping\" before it in cmd, so it\'ll look like this in command prompt: [ping (raw_input)]

How can I take this code, and take the raw_input and add "ping" before it in cmd, so it'll look like this in command prompt: [ping (raw_input)]

HERE开发者_JS百科 IS THE CODE:

          RS_usr = raw_input('input user here: ')
          from subprocess import Popen, PIPE, STDOUT


          p = Popen(['cmd.exe'], stdout=PIPE, stdin=PIPE, stderr=STDOUT)

          out,err = p.communicate(input=RS_usr)
          print(out)


If I understood you correctly you should change a couple of lines in your script:

p = Popen(['cmd.exe', '/k', 'set PROMPT=[Hello, (' + RS_usr + ')]' ], stdout=PIPE, stdin=PIPE, stderr=STDOUT)

out,err = p.communicate()
0

精彩评论

暂无评论...
验证码 换一张
取 消