$ date > '< abcd'
$ cat '< abcd'
<something>
$ tclsh8.5
% exec cat {< abcd}
couldn't read file " abcd": no such file or directory
whoops. This is due to the the specification of ‘exec’.
If an arg (or pair of args) has one of the forms described below then it is used by exec to control the flow of input and output among the subprocess(es). Such arguments will not be passed to the subprocess(es). In forms such as “< fileName”, fileName may either be in a separate argument from “<” or in the same argument with no intervening space”.
Is there a way to work around this?
Does the value have to be passed as an argument? If not, you can use something like this:
For filenames, you can (almost always) pass the fully qualified name instead. The fully qualified name can be obtained with
file normalize:But if you need to pass in an argument where
<(or>) is the first character, you’re stuck. Theexeccommand always consumes such arguments as redirections; unlike with the Unix shell, you can’t just use quoting to work around it.But you can use a helper program. Thus, on Unix you can do this:
(The subprogram just replaces itself with what you want to run passing in the argument you really wanted. You might need to use
string maporregsubto put backslashes in front of problematic metacharacters.)On Windows, you have to write a batch file and run that, which has a lot of caveats and nasty side issues, especially for GUI applications.