Subj : sweep To : Vitus Jensen From : Eddy Thilleman Date : Thu Mar 15 2001 03:55 am Hello Vitus, Wednesday 14 March 2001 02:18, Vitus Jensen wrote to Eddy Thilleman: ET>>>> Borland Pascal as DOS .EXE file and compiled it with Virtual ET>>>> Pascal/2 v2.1 build 243 as OS/2 .EXE file, and implemented it ET>>>> also in REXX. VJ> ... ET>> another example ET>> sweep for %a in (*.bak) do echo %a ET>> The compiled version is easier to use than the REXX variant. VJ> "easier to use"? I would expect the rexx variant to be easier to VJ> code. Yep, that's the difference. The REXX variant is somewhat easier to code (the pascal version is not difficult), but I found it more difficult to use the REXX variant with a "for %a in (*) do..." command (with and without a preceding 'cmd /c'), because sometimes I get errors, like: C:\>\os2\rexx\sweep for %a in (*.txt) do echo %a >> Command >> for %a in (*.txt) do echo %a >>> Sweep >>> C:\ SYS1079: a was unexpected at this time. Error? rc=1 C:\>\os2\rexx\sweep cmd /c for %a in (*.txt) do echo %a >> Command >> cmd /c for %a in (*.txt) do echo %a >>> Sweep >>> C:\ SYS1079: a was unexpected at this time. Error? rc=1 C:\>\os2\rexx\sweep cmd /c for %%a in (*.txt) do echo %%a >> Command >> cmd /c for %%a in (*.txt) do echo %%a >>> Sweep >>> C:\ Error? rc=31112 C:\>\os2\rexx\sweep cmd /c for %a in (*.txt) do echo %a >> Command >> cmd /c for %a in (*.txt) do echo %a >>> Sweep >>> C:\ SYS1079: a was unexpected at this time. Error? rc=1 Only one time I managed to get above construct working with the REXX variant. That's why I wrote the pascal version. ET>>>> Shall I post the source of all three? VJ>>> Are you sure it's the screen output? ET>> No, I'm not certain. VJ>>> If not, remove screen output from the program and rerun it. ET>> I've run it without screen output from all the sweep variants ET>> themselves, the only screen output is by the command run in each ET>> (sub)directory. The command in the compiled OS/2 version is run ET>> somewhat slower. VJ> There are larger gaps between execution in the different directories? Yes. VJ> That would mean that searching for directories is slower in VP/2 VJ> which is not to be expected or the startup of every command line takes VJ> longer (s.b.). I'm not sure about this. VJ> (how do you do it?), FindFirst/FindNext. Here is the source code of the pascal version: ------------------- begin of sweep.pas ------------------- uses dos; Var i : byte; quiet : boolean; CmdProc : string; CmdLine : string; function RunProg( Prog, Parm: string ): boolean; begin Exec( Prog, Parm ); if DOSError = 0 then RunProg := True else writeln( 'DOS error #', DOSError ); end; {$S+} Procedure AllDirs; var DR : SearchRec; Pad: string; begin GetDir( 0, Pad ); if not quiet then writeln( '>>> SWEEP >>> ' + Pad ); if RunProg( CmdProc, '/c' + CmdLine ) then begin FindFirst('*', Directory, DR); while (DosError = 0) do begin if (DR.Attr and Directory) = Directory then begin if ((DR.Name <> '.') and (DR.Name <> '..')) then begin ChDir( DR.Name ); AllDirs; ChDir( '..' ); end end; FindNext( DR ); end; end; end; {$S-} begin quiet := False; if ParamCount > 0 then begin CmdProc := GetEnv('COMSPEC'); CmdLine := ''; for i := 1 to ParamCount do begin if ((paramstr( i )[1] = '/') or (paramstr( i )[1] = '-')) and (upcase(paramstr( i )[2]) = 'Q') then quiet := True else CmdLine := CmdLine + ' ' + paramstr( i ); { /q ? } end; { all parameters } writeln( 'command:', CmdLine ); AllDirs; end; end. -------------------- end of sweep.pas -------------------- VJ> cmd.exe should already reside in the disk cache so the difference VJ> should be small or non existent. VJ> You are executing all commands through cmd.exe when coding in pascal. VJ> How do you do it in Rexx? Here is the source code for the REXX variant: ------------------- begin of sweep.cmd ------------------- /* * A sweep command for OS/2 * Recurses through directories from default and executes a command line */ '@echo off' ARG P1 dummy if P1 = '-Q' then parse arg dummy cl else do P1 = 0 parse arg cl end if cl = '/?' then signal GiveHelp if cl = '?' then signal GiveHelp if cl = '-?' then signal GiveHelp if cl = '' then signal GiveHelp signal on Syntax signal on Error signal on Failure signal on Halt CRLF = '0D'x || '0A'x n = setlocal() say '>> Command >>' cl call Exec( directory() ) n = endlocal() return Exec: procedure expose cl P1 parse arg path newdir = directory( path ) if newdir = path then do if P1 \= '-Q' then say '>>> Sweep >>>' directory() cl end Call SysFileTree path || "\*", 'dir', 'D' if datatype( dir.0 ) <> "NUM" then dir.0 = 0 do f = 1 to dir.0 name = substr( dir.f, 38 ) if (substr( dir.f, 32, 1 ) = 'D') then /* directory? */ call Exec( name ) end return Syntax: ErrorNr = rc Say 'Line' sigl':' Sourceline(sigl) Say 'Error' rc':' Errortext(ErrorNr) n = endlocal() exit Failure: say 'Failure, rc='rc n = endlocal() exit Error: say 'Error? rc='rc n = endlocal() exit Halt: n = endlocal() exit GiveHelp: say 'SWEEP.CMD' say ' Performs a command in the current directory and in all its subdirectories.' say '' say ' Usage: Sweep [-Q] command' say '' say ' -Q quiet, don''t display directories' exit -------------------- end of sweep.cmd -------------------- VJ> If you just let the already running copy of cmd.exe handle it we have VJ> a major difference: a new process for cmd.exe does not have to be VJ> started. Try to compare the following times, The DOS pascal version is equally fast as the REXX version, the OS/2 VP/2 version is slower (as I said). VJ> Rexx: sweep cmd /C "for %a in (*.bak) do echo %a" I can't execute this with the REXX version. single commands work with the REXX version, however. That's why I just give cd as the single command to all sweep versions. VJ> Pascal: sweep for %a in (*.bak) do echo %a for the pascal version, this is no problem. Any ideas? Greetings -=Eddy=- email: e.thilleman@freeler.nl e.thilleman@hccnet.nl .... Warp 4, Scotty... and close those damn Windows! --- GoldED/2 3.0.1 * Origin: The only thing more complicated than computers is TAX (2:280/5143.7) .