Author |
Message |
Da #1 / 18
|
 Arguments to exec with '<'
Hello, How the heck do I pass an argument to a program being run by 'exec' that starts with a '<' character? ie. How do I make it so that (argv[1] == "<hello>") Thanks, Dan
|
Mon, 28 Nov 2005 12:11:49 GMT |
|
 |
Marti #2 / 18
|
 Arguments to exec with '<'
Using single quotes around the "suspicious" argument should help, e.g. puts [exec echo '[lindex $argv 0]'] Greets, Martin Quote:
> Hello, > How the heck do I pass an argument to a program being run by 'exec' > that starts with a '<' character? > ie. How do I make it so that (argv[1] == "<hello>") > Thanks, > Dan
|
Mon, 28 Nov 2005 15:09:47 GMT |
|
 |
Andreas Leitge #3 / 18
|
 Arguments to exec with '<'
Quote:
>> How the heck do I pass an argument to a program being run by 'exec' >> that starts with a '<' character? >> ie. How do I make it so that (argv[1] == "<hello>") > Using single quotes around the "suspicious" argument should help, e.g. > puts [exec echo '[lindex $argv 0]']
But this will also pass the single quotes as part of the argument ! You can't. exec is just plain too "oversophisticated" for this task. There are some workarounds, such as exec'ing sh -c with a string, where all sh's metacharacters are explicitly backslash-escaped, but that is platform-dependent and sucks. Another one is, to execute some wrapper-prog, that undoes certain tricks to get through exec (like for example single-quotes). There have also been discussions about it in the past, and suggestions for alternative commands <http://mini.net/tcl/1353>, but the problem didn't yet occur often enough persuade anyone able to do it to implement it. In other words: Of those who had these itches, none knew how to scratch them, and of those who know, none had these itches. -- Nichts ist schlimmer als zu wissen, wie das Unheil sich entwickelt, und voll Ohnmacht zusehn muessen - das macht mich voellig krank... -- (Musical Elisabeth; "Die Schatten werden laenger")
|
Mon, 28 Nov 2005 16:01:13 GMT |
|
 |
Donal K. Fellow #4 / 18
|
 Arguments to exec with '<'
Quote:
> How the heck do I pass an argument to a program being run by 'exec' > that starts with a '<' character? > ie. How do I make it so that (argv[1] == "<hello>")
It's not as straight-forward as you might wish. The easiest way is to cheat (on Unix) like this: exec /bin/sh -c {exec /the/program '<hello>'} # Note that the word after the -c is a Bourne Shell script, not Tcl. Donal. --
"Give a concrete proposal, rather than just handwaving. Everything's obvious and easy if you don't have to do it yourself." -- Darren New
|
Tue, 29 Nov 2005 21:47:21 GMT |
|
 |
lvir.. #5 / 18
|
 Arguments to exec with '<'
:In other words: Of those who had these itches, none knew how to : scratch them, and of those who know, none had these itches. It would probably be easier - or at least more likely to result in a solution - for those with itches to learn how to scratch them than for those who know how to find time to scratch someone else's itch... -- The Tenth Annual Tcl/Tk Conference <URL: http://www.tcl.tk/community/tcl2003 > Even if explicitly stated to the contrary, nothing in this posting should be construed as representing my employer's opinions.
|
Sat, 03 Dec 2005 18:52:24 GMT |
|
 |
Andreas Leitge #6 / 18
|
 Arguments to exec with '<'
Quote:
>:In other words: Of those who had these itches, none knew how to >: scratch them, and of those who know, none had these itches. > It would probably be easier - or at least more likely to result in a > solution - for those with itches to learn how to scratch them than for > those who know how to find time to scratch someone else's itch...
Still, I'm really surprised how this issue can be of non-itch nature to even *anyone* actually using exec in any but most trivial ways. Some things I'll likely never understand. -- Nichts ist schlimmer als zu wissen, wie das Unheil sich entwickelt, und voll Ohnmacht zusehn muessen - das macht mich voellig krank... -- (Musical Elisabeth; "Die Schatten werden laenger")
|
Sat, 03 Dec 2005 21:49:21 GMT |
|
 |
Bryan Oakle #7 / 18
|
 Arguments to exec with '<'
Quote:
> Still, I'm really surprised how this issue can be of > non-itch nature to even *anyone* actually using exec > in any but most trivial ways. Some things I'll likely > never understand.
I've been writing tcl code for years and never had a problem with this (*). I suspect it's due to the fact that filenames and arguments to programs rarely include the '<' character. (*) Of course, part of this is luck. If someone named a file '<foo' and I passed that as an argument to exec I would have a problem.
|
Sat, 03 Dec 2005 22:34:21 GMT |
|
 |
Andreas Leitge #8 / 18
|
 Arguments to exec with '<'
Quote:
>> Still, I'm really surprised how this issue can be of >> non-itch nature to even *anyone* actually using exec >> in any but most trivial ways. Some things I'll likely >> never understand. > I've been writing tcl code for years and never had a problem with this > (*). I suspect it's due to the fact that filenames and arguments to > programs rarely include the '<' character. > (*) Of course, part of this is luck. If someone named a file '<foo' and > I passed that as an argument to exec I would have a problem.
See? all expressed "non-itch"-opinions about exec and meta-chars include the words "rarely", "luck" and the assumption that filenames are the only non-constant arguments that ever get passed to external programs. Whenever some proposals are discussed whose inclusion might (under very unlucky circumstances) cause different behaviour, then these (low) probabilities of failure are usually considered a big blocking point. E.g. who would accept adding a special argument "--" to exec or eval given that "--" might be a valid command. But everyone seems to accept, that '<hello' just won't ever occur as a valid argument to pass through to some exec'd program. -- Nichts ist schlimmer als zu wissen, wie das Unheil sich entwickelt, und voll Ohnmacht zusehn muessen - das macht mich voellig krank... -- (Musical Elisabeth; "Die Schatten werden laenger")
|
Sun, 04 Dec 2005 00:33:30 GMT |
|
 |
Darren Ne #9 / 18
|
 Arguments to exec with '<'
Quote:
> E.g. who would accept adding a special argument "--" to exec or > eval given that "--" might be a valid command.
Well, except that "--" usually works as essentially a quote character. In particular, commands that take "--" take that argument *because* they might have an argument that starts with a dash. So this isn't really a very good analogy. -- Darren New, San Diego CA USA (PST) Things to be thankful for, #187: There is no Chinese tradition of changing from shoes to slippers to get off an escalator.
|
Sun, 04 Dec 2005 02:12:37 GMT |
|
 |
Andreas Leitge #10 / 18
|
 Arguments to exec with '<'
Quote:
>> E.g. who would accept adding a special argument "--" to exec or >> eval given that "--" might be a valid command. > Well, except that "--" usually works as essentially a quote character. > In particular, commands that take "--" take that argument *because* they > might have an argument that starts with a dash. So this isn't really a > very good analogy.
That's not the point. Any "magic" string would have done it for the argument. something like exec >redir1 <redir2 $magic foo <hello> with $magic being some not yet specified magic-string, with the same purpose as "--" for commands accepting optional dash-preceded options. $magic could be "<>><<>" or "<>" or anything currently bogus. Whatever it is, I'm sure, that the (inevitable) "ugliness" or even slightest chance of an incompatibility would thwart such a change in the eyes of those who deny the fact that the current behaviour is much worse (for completely excluding strings starting with certain prefixes to be passed to the command). -- Nichts ist schlimmer als zu wissen, wie das Unheil sich entwickelt, und voll Ohnmacht zusehn muessen - das macht mich voellig krank... -- (Musical Elisabeth; "Die Schatten werden laenger")
|
Mon, 05 Dec 2005 00:55:36 GMT |
|
 |
Roy Terr #11 / 18
|
 Arguments to exec with '<'
Whatever it is, I'm sure, that the (inevitable) "ugliness" or even Quote: > slightest chance of an incompatibility would thwart such a change > in the eyes of those who deny the fact that the current behaviour > is much worse (for completely excluding strings starting with > certain prefixes to be passed to the command).
Who are you complaing about? My recollection of comments form Tcl core members is about priorities and implementation complexities - not refusal to consider changes. The exec and open code apparently share parsing code and this makes the fix difficult to preserve across platforms. Also there are currently no TIPS in existence to address this. Do you know of a TIP rejected? Just wondering what the sore spot is all about. Roy Quote: > -- > Nichts ist schlimmer als zu wissen, wie das Unheil sich entwickelt, > und voll Ohnmacht zusehn muessen - das macht mich voellig krank... > -- (Musical Elisabeth; "Die Schatten werden laenger")
|
Mon, 05 Dec 2005 04:28:10 GMT |
|
 |
lvir.. #12 / 18
|
 Arguments to exec with '<'
:Still, I'm really surprised how this issue can be of :non-itch nature to even *anyone* actually using exec :in any but most trivial ways. Some things I'll likely :never understand. I make certain I never create files with special characters in them... -- The Tenth Annual Tcl/Tk Conference <URL: http://www.tcl.tk/community/tcl2003 > Even if explicitly stated to the contrary, nothing in this posting should be construed as representing my employer's opinions.
|
Mon, 05 Dec 2005 19:59:00 GMT |
|
 |
lvir.. #13 / 18
|
 Arguments to exec with '<'
:
::Still, I'm really surprised how this issue can be of ::non-itch nature to even *anyone* actually using exec ::in any but most trivial ways. Some things I'll likely ::never understand. : :I make certain I never create files with special characters in them... I forgot to mention - the tcl code I write is for myself. That makes things easier for me. Certainly I understand someone else having an issue here. -- The Tenth Annual Tcl/Tk Conference <URL: http://www.tcl.tk/community/tcl2003 > Even if explicitly stated to the contrary, nothing in this posting should be construed as representing my employer's opinions.
|
Mon, 05 Dec 2005 20:01:05 GMT |
|
 |
Wojciech Kocja #14 / 18
|
 Arguments to exec with '<'
Uz.ytkownik Darren New napisa?: Quote: > Well, except that "--" usually works as essentially a quote character. > In particular, commands that take "--" take that argument *because* they > might have an argument that starts with a dash. So this isn't really a > very good analogy.
Actually, it could be done so that -- is not passed only if it is before *any* parameter passed on to the new process (including the command name). So: exec >somefile -- echo >somefile2 would print '>somefile2' into 'somefile'. However: exec >somefile rm -- -YOURFILE-.txt would pass -- to rm. Then you could argue that only incompatibility would be to call a command called '--', to which you would not specify any path. I doubt if any system has a command with such a name :) I'd really suggest looking into this as it is a very dangerous bug - it can be used in any script exec'ing anything to write arbitrary text to a file. It is really {*filter*}. -- WK
|
Tue, 06 Dec 2005 03:17:09 GMT |
|
 |
siva chelli #15 / 18
|
 Arguments to exec with '<'
Quote:
> Using single quotes around the "suspicious" argument should help, e.g. > puts [exec echo '[lindex $argv 0]'] > Greets, > Martin
what about including a space in front and then handling it in the exec'd program like this? set x " <hi there>" puts [exec /bin/echo $x] by the way, if I specify echo, I get 'not found'. How do I make Tcl to find what is in my path? Thanks, Siva Quote:
> > Hello, > > How the heck do I pass an argument to a program being run by 'exec' > > that starts with a '<' character? > > ie. How do I make it so that (argv[1] == "<hello>") > > Thanks, > > Dan
|
Sun, 11 Dec 2005 03:31:14 GMT |
|
|