Four Js Development Tools Forum

Discussions by product => Genero BDL => Topic started by: Sally Woolrich on February 24, 2010, 04:40:51 PM

Title: Creating a directory on the PC
Post by: Sally Woolrich on February 24, 2010, 04:40:51 PM
I would like to be able to create a directory on the PC so I can copy templates and data for mailmerge into it.  It will be far easier to do it from the code than by getting the folks managing the PCs to make sure the directory exists on every single PC, plus we can change it much more easily if we ever want.  The following test program shows the sorts of things I have tried, all to no avail.  Has anyone here done this?  If so, do you have a code fragment you can share, please?

(this is Genero 2.1 on Solaris, with the front-end running on Windows PCs)

Code (Genero) Select
main

define l_bool integer
define l_string string

let l_string = "mkdir c:\\zz"
display l_string

#    CALL ui.Interface.frontCall("standard", "execute", [l_string, 1], [l_bool])
    CALL ui.Interface.frontCall("standard", "shellexec", [l_string], [l_bool])

#    call winshellexec(  l_string ) returning l_bool
        if l_bool then
                display "OK"
        else
                display "Failed"
        end if
    display l_bool

end main
Title: Re: Creating a directory on the PC
Post by: Pierre-Nicolas RIGAL on February 24, 2010, 05:33:22 PM
Don"t forget that on windows mkdir is not an executable but a command of cmd.exe

(from my testing you even can't type "mkdir c:\zz" in windows "execute" box).

So you've first to run cmd.exe and then give the command, for instance:

let l_string = "cmd.exe /C \"mkdir c:\\zz\""

which can be called using shellexec.
Title: Re: Creating a directory on the PC
Post by: Sally Woolrich on February 24, 2010, 05:46:23 PM
Bingo - that works!  And it works with FrontCall as well.

Many thanks.  Case closed.
Title: Re: Creating a directory on the PC
Post by: Reuben Barclay on February 26, 2010, 12:44:44 AM
Pierre-Nicolas,

Is it potentially possible to take the library distributed with the Windows runner %FGLDIR%/lib/os.dll, place it in the %GDCDIR%/lib folder and call the same methods https://4js.com/techdocs/genero/fgl/devel/DocRoot/User/Ext_os_Path.html#METHODS via a front-end extension
https://4js.com/techdocs/genero/gdc/devel/DocRoot/User/FEExtensions.html

i.e

CALL ui.Interface.frontCall("os","mkdir",dirname, ok)

Reuben
Title: Re: Creating a directory on the PC
Post by: Pierre-Nicolas RIGAL on February 26, 2010, 08:26:02 AM
Not directly ; if the DLL you would like to load is not a GDC specific DLL, you'll need to rite a wrapper around it.

I don't know if os.DLL has been built the same way as C-extensions or if it has its own interface, but explanation below is valid whatever interface has been chosen:

To load a DLL dynamically, a program (gdc.exe or fglrun.exe) needs to know the function definition. With GDC, all functions must be like:

int functionName(struct frontEndInterface & fx);

where fx is a structure allowing the DLL to read in parameter and push out parameters.

with the DVM, the interface is much more complex, based on Informix. you can see it in f2c/fglExt.h. Most of Informix types can be passed, and a lot of functions / macro as proposed too. GDC api is very simple: call the function, get string / int parameter, return in / string parameter.

So what you would need to do is to make something like (thinking loud, I would not bet this compile directly ;) ) :
Code (cpp) Select
int mkdir(struct frontEndInterface & fx){
   QString dirname;
   fx.popQStriing(&dirname);
   if (loadDVMLib("os")) {
     int ret = execDVMFunction("mkdir", dirname);
     fx.pushInteger(ret, false);
     return 1;
  } else {
    return 0;
  }
}


and of couse loadDVMLib() and execDVMFunction() should be very similar to the code we have in the runtime.

While this is potentially doable, I would either try to make it with a bunch of shellexec calls, or with my own library:


Code (cpp) Select
int mkdir(struct frontEndInterface & fx) {
   QString dirname;
   fx.popQStriing(&dirname);
   QDir d(m_currentPath);

   return d.mkdir(dirname);
}