473,385 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Subprocess quote problem

Hi Folks,

I'm working on a script that executes a command with arbitrary
options. Most of its options works fine with subprocess, but at least
one (as far as I know) is giving me a headache. The program that I'm
trying to execute is Nmap, and the problematic option is the -iL, that
is used to indicate a file with the targets that nmap should scan.

If I open my terminal, and write: nmap -iL "/tmp/target_list" , nmap
picks the file, read it and scan every target written inside it.

But, if I try to use the same scan on my command execution script, it
makes nmap raise a strange error:

"Failed to open input file "/home/adriano/umit/test/targets" for reading
QUITTING!"
This is not a permission issue. I put this target_file file on /tmp
and set chmod 777 on it.
The script:

<code>
_stdout_handler = open(self.stdout_output, "w+")
_stderr_handler = open(self.stderr_output, "w+")
command = ['nmap', '-T', 'Aggressive', '-n', '-F', '-iL',
'"/home/adriano/umit/test/targets"']

command_process = Popen(command, bufsize=1,
stdin=PIPE,
stdout=_stdout_handler.fileno(),
stderr=_stderr_handler.fileno(),
shell=False)
</code>

The problem seens to be the double quoted path. But it doesn't make
any sense for me, as any other command that I put there works fine.

Any clue?
Cheeers!

--
Adriano Monteiro Marques
http://umit.sourceforge.net
py********@gmail.com

"Don't stay in bed, unless you can make money in bed." - George Burns
Aug 18 '06 #1
1 2465
In message <ma***************************************@python. org>, Adriano
Monteiro wrote:
"Failed to open input file "/home/adriano/umit/test/targets" for reading
QUITTING!"
Which is not the same as saying:

"Failed to open input file /home/adriano/umit/test/targets for reading
QUITTING!"

Spot the difference?
command = ['nmap', '-T', 'Aggressive', '-n', '-F', '-iL',
'"/home/adriano/umit/test/targets"']
Why exactly where you putting quotes within quotes in the path? That kind of
thing is only necessary when typing things on the shell command line, to
prevent the shell itself misinterpreting things, like putting word breaks
in the wrong places or having wrong behaviours triggered by special
characters.
Aug 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Grant Edwards | last post by:
I'm trying to use the py-gnuplot module on windows, and have been unable to get it to work reliably under Win2K and WinXP. By default, it uses popen(gnuplotcmd,'w'), but in some situations that...
2
by: smitty1e | last post by:
The first print statement does what you'd expect. The second print statement has rather a lot of rat in it. The goal here is to write a function that will return the man page for some command...
12
by: Eric_Dexter | last post by:
I am trying to modify a programming example and I am coming up with two problems... first is that I can't seem to pass along the arguments to the external command (I have been able to do that with...
23
by: Harishankar | last post by:
Hi, Sorry to start off on a negative note in the list, but I feel that the Python subprocess module is sorely deficient because it lacks a mechanism to: 1. Create non-blocking pipes which can...
3
by: topazcode | last post by:
I am using the subprocess module to run some shell commands on a Linux system: import subprocess output = subprocess.call('''ssh server1 "uptime"''', shell=True) The above assigns the output...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.