473,387 Members | 1,721 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,387 software developers and data experts.

Angle brackets in command-line arguments?

Hi all,

I am using someone else's script which expects input in the form of:

./script.py <arg1arg2

I was wondering if the angle-brackets here have a special meaning? It
seems like
they specify an input and output stream to use in place of the
console. I could not
find anything in the python manual or Python in a Nut-shell though.

Anyone know?
Thanks,
Keith
Jul 16 '08 #1
4 7409
On Wed, 16 Jul 2008 07:53:56 -0700, Keith Hughitt wrote:
I am using someone else's script which expects input in the form of:

./script.py <arg1arg2

I was wondering if the angle-brackets here have a special meaning? It
seems like they specify an input and output stream to use in place of the
console. I could not find anything in the python manual or Python in a
Nut-shell though.

Anyone know?
That's not Python's business but the command shell's. Those characters
are used for redirecting input and ouput from/to files in shells, so it
should be covered in the documentation of the shell you are using.
Including ways to protect the characters, so they reach the called program
in arguments.

Ciao,
Marc 'BlackJack' Rintsch
Jul 16 '08 #2
Keith Hughitt wrote:
I am using someone else's script which expects input in the form of:

./script.py <arg1arg2
<argis a common notation for "replace with argument value", so it
could be that they're just expecting you to type:

./script.py arg1 arg2

Alternatively, they meant

./script.py <arg1 >arg2

in which case arg1 and arg2 are filenames. This is most commonly used
with tools that process textfiles in some way. In the latter case, you
can try the script simply by running:

./script.py

and then typing the input to the terminal (use control-D on Unix or
control-Z on Windows to terminate).

Do the instructions use more meaningful names than "arg1" and "arg2"?

</F>

Jul 16 '08 #3
Keith Hughitt wrote:
Hi all,

I am using someone else's script which expects input in the form of:

./script.py <arg1arg2

I was wondering if the angle-brackets here have a special meaning? It
seems like
they specify an input and output stream to use in place of the
console. I could not
find anything in the python manual or Python in a Nut-shell though.

Anyone know?
Thanks,
Keith
--
http://mail.python.org/mailman/listinfo/python-list

In most Unix/Linux and related OS shells, the angled brackets *do*
specify input and output streams as you surmise. However, they are
*not* seen by the script as command line arguments. (And they are
*not* brackets, and do not need to be matched. )

For any command,
cmd < file
redirects the contents of file to cmd's standard input, which in Python
is accessed by reading from sys.stdin (use input or raw_input or
sys.stdin.read...)

Also for any command,
cmd file
redirects the output of cmd to the named file. In Python this can be
accessed using print, sys.stdout.write, ...

Anything written to sys.stderr will not be caught by the ">"
redirection, ans so will probably end up on the screen instead of in file.

Also various shells will provide similar functionality using a variety
of similar syntaxes: <<, >>, >&, and |, and so on.

Gary Herron
Jul 16 '08 #4
On Jul 16, 11:16*am, Gary Herron <gher...@islandtraining.comwrote:
Keith Hughitt wrote:
Hi all,
I am using someone else's script which expects input in the form of:
* * *./script.py <arg1arg2
I was wondering if the angle-brackets here have a special meaning? It
seems like
they specify an input and output stream to use in place of the
console. I could not
find anything in the python manual or Python in a Nut-shell though.
Anyone know?
Thanks,
Keith
--
http://mail.python.org/mailman/listinfo/python-list

In most Unix/Linux and related OS shells, *the angled brackets *do*
specify input and output streams as you surmise. *However, they are
*not* seen by the script *as command line arguments. *(And they are
*not* brackets, and do not need to be matched. )

For any command,
* cmd < file
redirects the contents of file to cmd's standard input, which in Python
is accessed by reading from sys.stdin (use input or raw_input or
sys.stdin.read...)

Also for any command,
* cmd file
redirects the output of cmd to the named file. *In Python this can be
accessed using print, sys.stdout.write, ...

Anything written to sys.stderr will not be caught by the ">"
redirection, ans so will probably end up on the screen instead of in file..

*Also various shells will provide similar functionality using a variety
of similar syntaxes: *<<, >>, >&, and |, and so on.

Gary Herron
Thanks all for the quick response. I should have known it was shell-
related. I haven't ever had to use this
kind of redirection before, mostly just the single-bracket version to
feed the contents of a file into some
command.

The reason it was causing me concern in the first place was that I was
trying to execute a python script
from Apache Ant, and it was failing. It turned out that when I escaped
the angle brackets in Ant, they were
there-after treated as normal command-line arguments, so when the
script was then executed, it just had
some additional values in sys.argv.

I ended up getting around the issue by creating a small bash-script
which simply wraps input in angle brackets
and then executes the python script itself. That way I didn't have to
escape anything in in Ant, and things
worked well.

Thanks everyone for taking the time to explain things to me. I really
appreciate the help :)

Take care,
Keith
Jul 16 '08 #5

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

Similar topics

5
by: Darren Grant | last post by:
Hi there, I've attempted to implement an Angle class. An Angle is a subset of an integer, where the range is [0,360). All other operations should be permitted. The code works, I think......
1
by: Greg | last post by:
I have an Access db (actually, about 60 of them) that has a table with a field named Q#. This table gets read into a dataset. In the dataset, the field is also called Q#. But when I try to update...
2
by: DotNetGruven | last post by:
We have a web service that returns a string which happens to be well formed XML. The client sees the string ok, except the angle brackets are HTML encoded ( &gt and &lt ). Is this expected...
15
by: cwsullivan | last post by:
Hi gang, I have a grid full of particles in my program, and I want to find an angle between two particles. I'm having trouble because it seems like the answer depends on whether or not the target...
2
by: Kenneth Porter | last post by:
If you email your users links and wrap the links in angle brackets, beware users using Yahoo Mail. It includes the trailing angle bracket in the link, preventing it from working. (This was...
3
by: Doraj | last post by:
Hello ! Here is my problem : I had some php scripts which worked well with php 4.0.5 (GD 1.6.2 according to phpinfo() ) and i put them on a new server with php 4.4.2 (and GD 2.0.28). Now,...
2
by: Peter | last post by:
Hi, I was wondering, can anyone tell me what statements in angle brackets are for in VB? For example, the default <System.Diagnostics.DebuggerStepThrough()thing that the IDE puts before the...
4
by: Nunzio | last post by:
I am trying to build an email address in PHP code using v5.1.2. All works well until I try to surround the email address with angle brackets. Every method I try causes the email address to...
2
by: laredotornado | last post by:
Hi, I'm using php 4.4.4. Maybe I'm misreading the docs, but in the imagettfbbox manual (http://us2.php.net/imagettfbbox), it says that text coordinates are the same regardless of what the angle...
6
by: jeffg | last post by:
I have created a site that uses a Doctype of XHTML Transitional and a character set of utf-8, in case any of this matters. I have validated every page and cleaned up all errors. IE displays the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.