Thanks guys.

This will get me past the first set of hurdles in my JOD port.  Once I have
something that passes my regression tests I will add linux to the JAL
distribution and this addon should appear on the linux side.

jdb

On Sun, May 8, 2011 at 6:19 PM, Joey K Tuttle <[email protected]> wrote:

> John,
>
> I shouldn't answer because I know nothing about Windows API - but I
> do use a lot of Linux native things in my J programs. If I get into
> things like Sockets, then I use the various covers for the 15!:x
> family - and something in that area may be required for your GUID
> query. I see that Bill Lam has provided a good answer for your first
> question. I offer a long winded version of his answer for the other 3.
>
> For your other questions I use 2!:0 (host) - not directly but as the
> following verb:
>
>   host =: [: 2!:0 '('"_ , ] , ' || true)'"_
>
> This returns the result of a Linux command as a text string - easily
> parsed in j to extract information. The reason for the complexity is
> that "host" returns a result, even if an error is generated on the
> Linux side - it also generates standard error output which is
> displayed in your session - e.g.
>
> Linux comand df -h displays filesystem information in human (-h)
> format, i.e. Bytes instead of blocks. e.g.
>
>    $x =. host 'df -h'
> 439
>    x
> Filesystem            Size  Used Avail Use% Mounted on
> /dev/mapper/set1-root
>                       906G  9.0G  851G   2% /
> none                  2.0G  212K  2.0G   1% /dev
> none                  2.0G     0  2.0G   0% /dev/shm
> none                  2.0G  364K  2.0G   1% /var/run
> none                  2.0G     0  2.0G   0% /var/lock
> none                  2.0G     0  2.0G   0% /lib/init/rw
> /dev/sda1             228M   36M  181M  17% /boot
>
>    $x =. host 'lskdjf'
> sh: lskdjf: not found
> 0
>    x
>
> I move or rename files a lot using host - since rename in Linux is mv
> (move) that operation happens very quickly, independent of file size.
> If the mv is from one file system to another, a copy (cp) is executed
> followed by removing (rm) the source file - this takes time depending
> on the size of the file.
>
> If you want control of your session while a long operation is
> running, I suggest using 2!:1 (spawn) - and even there you need to
> fork the task on the Linux side, here are some examples:
>
>    host 'ls -l JAusten2.toast '
> -rw-r--r-- 1 jkt jkt 4170022912 2010-12-24 20:25 JAusten2.toast
>
>    $x =. 2!:1  'cp JAusten2.toast  bigfile &'
> 0
>
> The above result happens immediately - but the process started by the
> ending & keeps running, as shown by
>
>    host 'ls -l bigfile'
> -rw-r--r-- 1 jkt jkt 945422336 2011-05-08 15:51 bigfile
>
>    host 'ls -l bigfile'
> -rw-r--r-- 1 jkt jkt 4170022912 2011-05-08 15:52 bigfile
>
> I rarely need to copy large files so I don't often use spawn (2!:1)
> and host works fine for mv -
>
>    host 'mv bigfile largefile' NB. this happens very quickly
>
> That is in 4 milliseconds on my machine. Even if the file is several
> megabytes, a copy is reasonably quick, so again, I rarely use spawn.
>
> I think host and spawn can likely meet your requirements nicely by
> using regular Linux facilities (along with a little parsing, ": and
> ".  on the J side).
>
> - joey
>
>
> At 2:07 PM -0500 11/05/08, John Baker wrote:
> >Greetings J'ugglers,
> >
> >In the last week I have set up a Linux Ubuntu box and installed J 7.01 on
> >it.  The JGTK version is very zippy in this environment and I am looking
> >forward to porting JOD to Linux systems.
> >
> >JOD is 99% J with a few key WINAPI calls.  I need to find Linux
> equivalents
> >to the following WINAPI calls. I am new to Linux and unfamiliar with Linux
> >APIs so if any of you could provide pointers I would appreciate it.
> >
> >The calls I am looking to replace are:
> >
> >NB. generates a GUID with dll call
> >genguid=:'ole32.dll CoCreateGuid i *c'&cd
> >
> >NB. returns free disk space
> >'kernel32 GetDiskFreeSpaceA i *c *i *i *i *i' cd y;(,0);(,0);(,0);(,0)
> >
> >NB. Win32 procedure that copies files
> >copyfile=:'kernel32 CopyFileA i *c *c i'&cd
> >
> >NB. Win32 procedure that moves/renames files
> >movefile=:'kernel32 MoveFileA i *c *c'&cd
> >
> >--
> >John D. Baker
> >[email protected]
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
John D. Baker
[email protected]
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to