473,408 Members | 2,405 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,408 software developers and data experts.

sys.argv with quoted strings as option argument

Hi everyone,

I would like to send an option argument which is a quoted string with
whitespaces to a python program. For example:

$ ./myprogram.py --includedir="/usr/include /usr/local/include"
--libdir="/usr/lib /usr/local/lib"

However, sys.argv breaks the arguments whenever it encounter spaces,
like this:
['./myprogram.py', '--includedir=/usr/include', '/usr/local/include',
'--libdir=/usr/lib', '/usr/local/lib']

So I can't seem to use getopt or optik to process such cases. Is there a
good way where I can preserve such option arguments with whitespaces?

satya

--
Satya Nanda Vel Arjunan
Institute for Advanced Biosciences
Keio University
http://satya.host.sk/

Jul 18 '05 #1
1 2132
> However, sys.argv breaks the arguments whenever it encounter spaces,
like this:
['./myprogram.py', '--includedir=/usr/include', '/usr/local/include',
'--libdir=/usr/lib', '/usr/local/lib']

So I can't seem to use getopt or optik to process such cases. Is there a
good way where I can preserve such option arguments with whitespaces?


Under Linux, this works. So most probably this is a problem of your shell
(under windows?) Anther solution might be to specify every argument with
its own key like this:

../myprogram --include-dir=foo --include-dir=bar

Using getopt, you can build up the list on your own.

Diez
Jul 18 '05 #2

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

Similar topics

9
by: Vinu | last post by:
Hai when i compile the cpp file(cmdargs.cpp) i attached the output below the program int main(int argc, wchar_t* argv) { std::wcout<<L"Name of the Program is "<<*argv<<std::endl;...
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
13
by: Vinu | last post by:
hai i have a problem i con't able to print the values of argv int main(int argc, wchar_t* argv) { return o; }
5
by: mwebel | last post by:
Hi, is is also a C question but the program im writing is in C++ and it applies as well so: i have a program in the "main(int argc, const char ** argv)" and i want to make a library. for...
5
by: jerry | last post by:
I need to modify the code of a command-line tool. The source code starts out like this: int main(int argc, char *argv) { int ch, A, B ; while ((ch = getopt(argc, argv, "AB")) != -1)...
56
by: subramanian100in | last post by:
The standard allows that we can copy strings onto arg, arg, etc. Why is it allowed ? What can be the maximum length of such a string that is copied ?
4
by: interec | last post by:
Hi Folks, I am writing a c++ program on redhat linux using main(int argc, wchar_t *argv). $LANG on console is set to "en_US.UTF-8". g++ compiler version is 3.4.6. Q1. what is the encoding of...
11
by: vicky | last post by:
hi all, please tell me with example, how the *argv point to the the no of strings.
2
by: Ben Bacarisse | last post by:
candide <candide@free.invalidwrites: argv can't be an array. It is a function parameter and arrays can't be passed to functions in C. There is indeed an array "out there" but all main can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.