Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flummoxed by quotes in exec line

Status
Not open for further replies.

lucianoes

Programmer
Dec 29, 2002
2
BR
Hi, everyone.

I am a Tcl newbie. Just started learning it, a few days ago, and I am quite surprised at how easy, powerful and productive it is. I didn't want to ask help in a list because I already subscribe to so many and Tcl has been so easy until now that I thought I wouldn't need it. But this is really flummoxing me.

I am making a GUI to run sed. Why? Because I love sed, it is a good idea to practice and learn Tcl. My program will have Undo/Redo, History saving and retrieving, convenient frequently-used RE management etc.


So I have two input boxes: the first one lets you enter any sed script that you would place in quotes, like this:
sed "s/find/replace/g"

The relevant code:
if {[focus -displayof $w.userinput] == ".main.userinput.sed1"} {
set mySed $mySed1
set myResult [exec ssed "$mySed" $tempfile]
}


The second input box will let you write options like -r or -n before the scripts, so it only automates "sed". You'll have to write everything else. Like this:
sed -r -n "/find (this group)/p"

The relevant code:
if {[focus -displayof $w.userinput] == ".main.userinput.sed2"} {
set mySed $mySed2
set myResult [exec ssed $mySed $tempfile]
}

That second part doesn't work. I always get this error:
C:\PROGS\GNU\ssed.exe: -e expression #1, char 1: Unknown command: `"'

I spent a ridiculous amount of time trying to find a correct escape syntax, but couldn't make it work.

After a lot of fruitless tries, I tried this kludge:
if {[focus -displayof $w.userinput] == ".main.userinput.sed2"} {
set mySed $mySed2
set mySedRun "ssed -R $mySed $tempfile"
set myResult [exec $mySedRun]
}

... and got this error:
couldn't execute "ssed -R "s\A\XXXXXX\g" c:\windows\temp\sedition1.txt": no such file or directory

Tcl inverted my slashes!

You see "ssed.exe" so many times because I am using super-sed, but that doesn't matter. Tcl is obviously misinterpreting my exec command.

BTW, I was playing with regex and tkcon the other day and could not find a way to replace slashes with inverted slashes and/or vice-versa. Should I think there is some relation to the problem mentioned above?

Thank you for any input.
Luciano
 
Try like this:
exec sed -e "s/new/old/g" filename.
It works fine here.
 
Of course it does, if you open a shell and run it. But if I type that into the input box, Tcl will parse it wrong and produce an incorrect command, like I explained.

Luciano
 
I think your script is running under Windows and that Windows tranforms the \ into / because it tries to restitute the path syntax expected by many Windows applications.
(It's MS challenge to be smarter than needed).

I believed that this occurred only with the first argument (and then marsd' solution would be fine).

I don't know how to do to avoid that :-(
If you're using NT(4/200/XP) have you tried to explicitely use start.exe, cmd.exe or command.exe?

HTH

ulis


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top