BaanTech
10th April 2003, 16:55
Is it possible to use assigned values in shell commands invoked from with Baan scripts ?
eg. instead of using ret = shell("rm $BSE/tmp/file", 0) I want
to create a command knowing that:
file.path = "${BSE}/lib/user"
file.name = "p" & ttaad200.user
... and "/" is between the path and name.
I can combine the path/slash/name into 1 string.
The file name will change per user.
If not then I can always use tools dll - ttdllfilehand to
accomplish what I need.
Thanks.
BaanTech
jaapzwaan
10th April 2003, 17:35
If the following works:
shell("rm $BSE/tmp/file", 0)
Then, the following should also work:
shell(sprintf$("rm %s/p%s", file.path, ttaad200.user))
or
shell(sprintf$("rm $BSE/lib/user/p%s", ttaad200.user))
where e.g.
file.path = "${BSE}/lib/user"
ttaad200.user = "baantech"
NPRao
10th April 2003, 19:52
This is how I do it-
function remove.user.files(string fname(80))
{
long fp
string fpath(256)
fpath = bse.dir$() & "/lib/user/" & fname
fp = seq.open(fpath, "r")
if fp > 0 then
e = seq.close(fp)
e = file.chmod(fname, S_IRWXU + S_IRGRP + S_IROTH)
e = file.rm(fpath)
if not e then
mess("zmadms0029", 1) |* Invalid Operation
choice.again()
endif
endif
}
You can then place this function in a DLL and call it whenever you need it.
BaanTech
10th April 2003, 20:17
I'm using copy.file via ottdllfilehand and then the shell command
to back up my file and remove. I could have also used shell(cp...)
I'm also using shell(sprintf$("chmod 775 %s", current.user.file), 0)
to reset permissions.
Thanks.
jaapzwaan
11th April 2003, 10:38
THe example of N. Prashant Rao is better (as always :-) )
Using the file.copy, file.chmod, etc functions, you make sure you work OS independent and future proof.
Note that the shell function is no longer supported in later versions, because of its OS dependency.
See also the notes in the manual (http://www.baanboard.com/programmers_manual_baanerp_help_functions_starting_and_stopping_programs_shell)
Regards,
Jaap Zwaan