system command

Brian K. White brian at aljex.com
Tue Nov 1 22:11:38 PST 2005


----- Original Message ----- 
From: "Dennis Malen" <dmalen at malen.com>
To: "Fairlight" <fairlite at fairlite.com>; <filepro-list at lists.celestial.com>
Cc: "pmahler" <pmahler at malen.com>
Sent: Tuesday, November 01, 2005 5:50 PM
Subject: Re: system command


> Mark,
>
> I have tried everyone's suggestions and then some. I used the redirecting 
> suggestion, I used your changes in the script, I have done what Ken 
> requested. It does not work.
>
> I have also tried the sh -c.
>
> You say it worked on your system flawlessly. What worked! Did it execute 
> the file or did you just see a return script.
>
> How do you know it worked. I used all your scripts and it didn't work..
>
> My last suggestion did work if the script was in an executable file. My 
> only problem is being able to append to the line so I can put in the 
> variable record number. Note, it must append to the line and not go to the 
> next line. If anyone knows how to do it, please let me know.
>
> I had to develop a work around after the suggestions did not work. You 
> can't blame me for that.

If you are using echo to write output, and if the shell the echo command is 
built into supports slash codes by default, then the way you write a line 
and append to the same line later is to tell the echo command not to add a 
trailing newline, which it will add by default.

On a sco unix box, the default shell is /bin/sh, and sco's /bin/sh 
interprets slash codes by default, and so in that context you would add \c 
to the very end of the echo command, but inside the quotes.
That's inside the quotes to the echo command, not just inside the quotes to 
the system command.

try this manually at the command line:

# echo "aaa\c" > file.txt
# echo "bbb" >> file.txt
# cat file.txt

If the OS is linux or if for whatever other reason you're really using bash, 
then you need echo -e "aaa\c" or echo -n "aaa"

man sh and look for stuff about echo. (type /echo and hit [Enter] while in 
the pager viewing the page)

That said, this is the most idiotic and backwards way to accomplish 
something so simple it's not funny.
Just figure out the necessary backslash nesting necessary and keep it a 
simple echo command.
It's a little tedious but so? Welcome to programming. Handling backslashes 
inside multiple nested layers of backslash-eaters is like that. You often 
can't just try what seems likely once and expect it to work. It's not 
uncommon to need 4 or more backslashes for every 1 that you need to reach 
the final destination when every handler along the way will interpret them 
and eat half of those present.

You have to be a bit more methodical, less haphazard and less guessing in 
you approach to solving the problem.

You have a string that ultimately you know will cause tiny term to perform 
an act.

Start by figuring out what it takes to get fp and the system command and the 
shell inside that and the echo command inside _that_ , to produce a string 
that has all the easy simple parts right, and don't worry about escape 
characters and other codes. Just get it so it makes a string the visually 
looks close, but with some orinary character in place of the special cases.

Then figure out what it takes to get a single escape character.

Then start replacing bits of the string with variables and get the 
unquote/concat/requote right bit at a time each time you add another break 
in the string.

Forget trying to get the final result all at once. Obviously you are not 
fluent enough with the shell or with the basic nature of handling nested 
quoting, and special codes withing nested layers of things that interpret 
some of the same special codes.

Another trick you may be able to use is to use single-quotes for the echo 
command inside the filepro system command, and use fp to create the escape 
character and other special characters like that \015
by using chr(). Single quotes have a special meaning to the shell, and so 
sometimes you can't use them, but it looks like in this case you can.

My offhand guess at one possible way to do the following with single quotes 
to avoide the backslash mess is:
pa="\\"\\033&oFvar
searchnum="{rn{";CompileFile(\\\\"260268.cs\\\\");\\015\\""

Is this:
system "echo '" { chr("27") { "&oFvar searchnum=" { rn { 
";CompileFile(\"260268.cs\");" { chr("13") { "'"

That should result in the shell seeing a command that looks like this:

echo '^[&Fvar searchnum=12345;CompileFile("260268.cs");^M'

Which should result in tiny term seeing this:

^[&Fvar searchnum=12345;CompileFile("260268.cs");^M^K

The echo command will add a linefeed to that, and the ^M (aka \015, aka \r, 
aka chr("13"), aka carriage-return) comming immediately before the linefeed 
(^K, aka \010, aka \n, aka chr("10"), aka line-feed) added by default by 
echo at the end of the line and together with that linefeed, collectively 
just forms a normal DOS line-ending.

The ^[ is just another way of saying <a single byte, the escape character, 
goes here>
It represents Ctrl-[ and it's litteral in that you can actually type 
Ctrl-[ (as a hot-key, hold down Ctrl, and press [ while doing so), and it's 
the same as if you'd pressed the escape key.
Just like you can type ^H (Ctrl-H) instead of backspace, or ^M instead of 
Enter.
Your original \033 is just a way to tell the shell & it's echo command to 
produce an escape character.

Also try doing this:
build up what you think is a system command that does roughly what you want, 
again without attempting to get any special quoting or special characters.
Inside the quotes at the end of the system cmmand, but at the very end, 
outside the quotes for the echo command, add >/tmp/capture like Mark and Ken 
suggested.

If the file looks ok then try adding one bit of complication, like say the 
quotes that ned to go around the file name inside the parens.
and run it again.
If the file looks ok, and now has quotes where they should be, then add 
anther bit, like replacing a static value with a variable and run again.

When you get to where you are trying to add the escape and carriage return 
characters, after you run the fp process to create the temp file, view the 
temp file with hd or od.
like this:
# hd < /tmp/capture

The above string, if it starts off with an escape character, will look like 
this:

 # echo "\033&oFvar searchnum=12345;CompileFile(\"123456.cs\");\r" |hd
0000    1b 26 6f 46 76 61 72 20  73 65 61 72 63 68 6e 75   .&oFvar searchnu
0010    6d 3d 31 32 33 34 35 3b  43 6f 6d 70 69 6c 65 46   m=12345;CompileF
0020    69 6c 65 28 22 31 32 33  34 35 36 2e 63 73 22 29   ile("123456.cs")
0030    3b 0d 0a                                           ;..
0033
#

You are looking to match up the hex pairs on the left with the visual 
characters on the right.
Each pair is one character.
Unprintable characters are shown as "." on the right.
notice my echo command starts with \033
notice the first hex pair is 1b (same value, but in hex)
notice on the right the first character is a "."

You can also tell hd to use either decimal or octal to show the special 
characters too, to match either the fp chr() command or the echo \nnn codes 
to make it easier to spot the discrepency between your original command and 
the final result. If you used chr in fp (decimal), the use hd -bd or hd -cd, 
if you used echo \nnn codes (octal), then use hd -bo or hd -co

decimal: notice 27 at the beginning, and 13, 10 at the end
# echo "\033&oFvar searchnum=12345;CompileFile(\"123456.cs\");\r" |hd -bd
0000     27  38 111  70 118  97 114  32  115 101  97 114  99 104 110 117
0010    109  61  49  50  51  52  53  59   67 111 109 112 105 108 101  70
0020    105 108 101  40  34  49  50  51   52  53  54  46  99 115  34  41
0030     59  13  10
0033
#

octal, recognize the 033 at the beginning and the 015 at the end?
# echo "\033&oFvar searchnum=12345;CompileFile(\"123456.cs\");\r" |hd -bo
0000    033 046 157 106 166 141 162 040  163 145 141 162 143 150 156 165
0010    155 075 061 062 063 064 065 073  103 157 155 160 151 154 145 106
0020    151 154 145 050 042 061 062 063  064 065 066 056 143 163 042 051
0030    073 015 012
0033

or these ways are a little easier to read, they only show the really 
non-printable characters as decimal/octal codes and the print the plain 
character or the common backslash notation where possible:

decimal
# echo "\033&oFvar searchnum=12345;CompileFile(\"123456.cs\");\r" |hd -cd
0000     27   &   o   F   v   a   r        s   e   a   r   c   h   n   u
0010      m   =   1   2   3   4   5   ;    C   o   m   p   i   l   e   F
0020      i   l   e   (   "   1   2   3    4   5   6   .   c   s   "   )
0030      ;  \r  \n
0033

octal
# echo "\033&oFvar searchnum=12345;CompileFile(\"123456.cs\");\r" |hd -co
0000    033   &   o   F   v   a   r        s   e   a   r   c   h   n   u
0010      m   =   1   2   3   4   5   ;    C   o   m   p   i   l   e   F
0020      i   l   e   (   "   1   2   3    4   5   6   .   c   s   "   )
0030      ;  \r  \n
0033

if you get "nothing" in your /tmp/capture
then add stderr to the capture and see if you get a clueful error message in 
the capture fill this time.

system "echo ......>/tmp/capture 2>&1"

more /tmp/capture
sh: CompileFile: no such command

would tell you something is wrong with the quoting before the first ";" for 
example.

Brian K. White  --  brian at aljex.com  --  http://www.aljex.com/bkw/
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro  BBx    Linux  SCO  FreeBSD    #callahans  Satriani  Filk!





then do 



More information about the Filepro-list mailing list