[fpc-pascal]building a command string

DONALD PEDDER jims_son at jedi.apana.org.au
Tue Sep 23 02:12:42 CEST 2003


Hi all,

   The previous compiler I used didn't have Exec or a way to get
parameters, so I am currently fooling around with these new toys (needless
to say, my old programs were pretty inflexible, with hard-coded filenames,
etc.).
   In particular, I am trying to build and execute a DOS command using a
filename given as a parameter (as opposed to a hard-coded filename) which
makes a backup copy of a file before I start fooling with the original
file (in case of a program crash part-way through). I know someone will
want to tell me I can write the program to do that directly, rather than
using DOS, but I'm trying to learn how not to re-invent the wheel. :-)
i.e. I'm trying to learn how to use the functionality that already exists
there in the OS (copy just being one of the many commands available). I've
got my program working with a hard-coded filename, I just haven't quite
got it sorted with passing a filename to it.

   Below is the current state of my code. I am getting "invalid TSS" at
the point I have noted. I don't even know what a "TSS" is! I guess it's
something to do with strings (I haven't used strings much before either -
something else lacking in my previous compilers). I searched the doco, but
couldn't find what I was looking for.

   I originally tried this with paramstr rather than argv, but changed due
to type mis-matches. I sorted out the types now, but there's obviously
some piece of knowledge I am missing about argv/strings that is causing
this not to work.

   If someone can tell me how to fix the following, or alternatively tell
me a better way to do this, that would be appreciated. Thanks.

   I am currently using "testfile" as the parameter (hence the "dir
test*").

Exec(GetEnv('COMSPEC'),'/c dir test*');
tempstr1:='/c copy';
tempstr2:=' ';
tempstr:=strcat(tempstr1,tempstr2);
writeln(tempstr,'*');
tempstr1:=tempstr;
tempstr2:=argv[1];
tempstr:=strcat(tempstr1,tempstr2);
writeln(tempstr,'*');
tempstr1:=tempstr;                         < program
tempstr2:=' ';                             < crashes
tempstr:=strcat(tempstr1,tempstr2);        < here
writeln(tempstr,'*');
tempstr1:=tempstr;
tempstr2:=argv[1];
tempstr:=strcat(tempstr1,tempstr2);
writeln(tempstr,'*');
tempstr1:=tempstr;
tempstr2:='.bak /v';
tempstr:=strcat(tempstr1,tempstr2);
writeln(tempstr,'*');
Exec(GetEnv('COMSPEC'),tempstr);
Exec(GetEnv('COMSPEC'),'/c dir test*');




More information about the fpc-pascal mailing list