[M3devel] new problem on NT386
Olaf Wagner
wagner at elegosoft.com
Wed Jan 23 19:32:16 CET 2008
Quoting Randy Coleburn <rcoleburn at scires.com>:
> Olaf:
>
> The pipe symbol is used by reactor in the quake exec() calls. I did
> not program this; it was done by CMass Inc. My experience has been that
> the pipe worked as a command separator in the quake exec() call, even on
> the Unix systems. I agree it looks strange, but then, I'm not a quake
> expert.
Is this documented anywhere? The online doc says
exec(...) The arguments are catenated and passed to the operating
system to be executed as a child process. The command may start `-' or
`@'. These are stripped before the command is passed to the command
interpreter. A prefix of `@' indicates that the default action of
printing the command to the standard output stream before execution
should be overridden. A prefix character of `-' overrides quake's
default action of aborting if it detects an error return code after
executing the command.
I've never seen it, and it seems a really strange choice to me, since
it would make it impossible to use pipes within a command.
OK, I've found it, but didn't know it ever existed ;-)
Here is the diff:
% cvs diff -u -r 1.3 -r 1.4 m3-sys/m3quake/src/QMachine.m3
Index: m3-sys/m3quake/src/QMachine.m3
===================================================================
RCS file: /usr/cvs/cm3/m3-sys/m3quake/src/QMachine.m3,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -u -r1.3 -r1.4
--- m3-sys/m3quake/src/QMachine.m3 25 Jun 2003 14:36:32 -0000 1.3
+++ m3-sys/m3quake/src/QMachine.m3 16 Oct 2005 13:43:32 -0000 1.4
@@ -1354,7 +1354,6 @@
quake_in : Pipe.T;
process_out : Pipe.T;
wr : Wr.T := CurWr (t);
- wd : TEXT;
inbuf : ARRAY [0..255] OF CHAR;
BEGIN
info.command := "";
@@ -1396,8 +1395,6 @@
Err (t, "write failed" & OSErr (ec));
END;
- wd := ExtractInitialDir (info.command);
-
args [0] := t.sh_option;
args [1] := info.command;
n_shell_args := 2;
@@ -1410,7 +1407,7 @@
(* fire up the subprocess *)
handle := Process.Create (t.shell, SUBARRAY (args, 0, n_shell_args),
stdin := stdin, stdout := process_out,
- stderr := process_out, wd := wd);
+ stderr := process_out);
(* close our copy of the writing end of the output pipe *)
process_out.close ();
LOOP (* send anything coming through the pipe to the quake
output file *)
@@ -1439,38 +1436,6 @@
RETURN info;
END ExecCommand;
-PROCEDURE ExtractInitialDir (VAR cmd: TEXT): TEXT =
- (* search for "cd <dir> |" or "cd <dir> ;" prefix in "cmd".
- If it's found, return "<dir>" and remove the prefix from "cmd".
- Otherwise, return "NIL". *)
- VAR
- len := Text.Length (cmd);
- buf : ARRAY [0..99] OF CHAR;
- start, stop: INTEGER;
- dir: TEXT;
- BEGIN
- IF (len < 5) THEN RETURN NIL; END;
- Text.SetChars (buf, cmd);
- start := 0;
- WHILE (start < len) AND (buf[start] = ' ') DO INC (start); END;
- IF (start+4 >= len) THEN RETURN NIL; END;
- IF (buf[start] # 'c') THEN RETURN NIL; END;
- IF (buf[start+1] # 'd') THEN RETURN NIL; END;
- IF (buf[start+2] # ' ') THEN RETURN NIL; END;
- INC (start, 3);
- WHILE (start < len) AND (buf[start] = ' ') DO INC (start); END;
- stop := start;
- WHILE (stop < len) AND (buf[stop] # ' ')
- AND (buf[stop] # '|') AND (buf[stop] # ';') DO INC (stop); END;
- IF (stop <= start) THEN RETURN NIL; END;
- dir := Text.FromChars (SUBARRAY (buf, start, stop - start));
- WHILE (stop < len) AND (buf[stop] = ' ') DO INC (stop); END;
- IF (stop >= len) THEN RETURN NIL; END;
- IF (buf[stop] # '|') AND (buf[stop] # ';') THEN RETURN NIL; END;
- cmd := Text.Sub (cmd, stop+1);
- RETURN dir;
- END ExtractInitialDir;
-
PROCEDURE KillProcess (handle: Process.T) =
BEGIN
IF (handle # NIL) THEN
Obviously it has been remove by rillig (Robert Illig?):
revision 1.4
date: 2005-10-16 13:43:32 +0000; author: rillig; state: Exp; lines: +1 -36;
Removed the superfluous and error prone ExtractInitialDir procedure,
which had tried to parse the shell command, and if it starts with "cd ",
changed to that directory itself.
So it only looked for cd dir | and then changed the directory
accordingly, but it really was an undocumented hack and is not needed.
I'd suggest to just use 'cd dir &&' instead. If that doesn't work,
please let me know.
A grep through the sources for 'cd .*\|' should reveal all occurences.
If you need more enhanced execution functions, I can also contribute
a module with much better abstractions for running commands.
Olaf
--
Olaf Wagner -- elego Software Solutions GmbH
Gustav-Meyer-Allee 25 / Gebäude 12, 13355 Berlin, Germany
phone: +49 30 23 45 86 96 mobile: +49 177 2345 869 fax: +49 30 23 45 86 95
http://www.elegosoft.com | Geschäftsführer: Olaf Wagner | Sitz: Berlin
Handelregister: Amtsgericht Charlottenburg HRB 77719 | USt-IdNr: DE163214194
More information about the M3devel
mailing list