-1

The scripts launches the application nmap. Only it doesn't print out the var to the application nmap. It does however if I print them separately.

Looking for some suggestions, many thanks.

Image script - Image output

Script:

import os
import subprocess

xIP=input("Please enter IP-address to use on NMAP port-scan: ")
xOP=input("Please apply options to add on port-scan: ")

print("Entered values: ", xIP + xOP)

command = "nmap print xIP xOP"
#os.system(command)
subprocess.Popen(command)

input("Press ENTER to exit application...")
Olivier
  • 3
  • 1
  • 1
    Have you done any debugging? As an aside, please do not share information as images unless absolutely necessary. See: https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors, https://idownvotedbecau.se/imageofcode, https://idownvotedbecau.se/imageofanexception/. – AMC Sep 28 '20 at 22:29
  • Yes, I did any debugging, and I know it's the line - command = "nmap print xIP xOP". I did post the images to provide extra information. – Olivier Sep 29 '20 at 09:32

2 Answers2

1
command = "nmap print xIP xOP"

This line is the issue. First, as Uriya Harpeness mentioned, subprocess.Popen() works best when the command is split into pieces in a collection like a list. Instead of using str.split() as they suggest, shlex.split() is designed for this, as the example in the Popen docs shows.

However, the other issue you're having is that you've placed your variable names into a string literal, so they're just being treated as part of the string instead of being evaluated for their contents. To get the behavior you want, just reference the variables directly:

command = ["nmap", "print", xIP, xOP]
subprocess.Popen(command)
MattDMo
  • 100,794
  • 21
  • 241
  • 231
0

See here: https://docs.python.org/3/library/subprocess.html#subprocess.Popen

Split the program name and the arguments, the first item in the list it expects is the name of the program to run.

In your case, subprocess.Popen(command.split(' ')) may suffice.

Uriya Harpeness
  • 628
  • 1
  • 6
  • 21