bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] working with )HOST


From: Louis de Forcrand
Subject: Re: [Bug-apl] working with )HOST
Date: Sun, 6 Mar 2016 01:39:11 +0100

Correction; to feed it a var, simply catenate the file name like:
FILE←¯1↓‘)HOST cat ‘ , filename←’relative_or_absolute/path/to/blablabla.txt’
Keep in mind your current dir is the one you started GNU APL from, so it can
change. Using ~/… or an absolute path is probably safer.

Louis

On 06 Mar 2016, at 01:35, Louis de Forcrand <address@hidden> wrote:

I am not very good with files and such, but from what I understand:

      ⎕←T←⊃¯1↓⍎')HOST date'
Sun Mar  6 01:11:48 CET 2016

      ⍴T
2 28

So you can save the result of )HOST in a variable if you use
⍎. To feed it a var, I would try something like:

      ]BOXING 2
      ⎕←FILE←⍎')HOST cat test.txt'
 hello, world  This file was written in my $HOME directory.  0  
      ⍴FILE
5
      FILE
.→-----------. .⊖. .→-------------------------------------------. .⊖. .→-.
|hello, world| | | |This file was written in my $HOME directory.| | | |0 |
'------------' '-' '--------------------------------------------' '-' '--'
Several things to note here. First of all, linefeeds / carriage returns / whatever
you want to call them in the file I read seemed to mark nested array ends, and
it seems that those LFs were lost. I don’t know how GNU APL handles LF chars,
so I would recommend you either keep the array boxed or disclose it like I did
in the first example (∊ enlisting it simply catenated all the lines together, as
the LFs were represented by ⊂⍬, boxed empty vectors).

Second, if you’re reading this Jürgen, note that even though ]BOXING was set
to 2, the result of ⎕←FILE is not boxed.

IMHO this is potentially the cleanest way to read a file. I have no idea how to tie
files and stuff like that.

Best of luck,
Louis

On 05 Mar 2016, at 03:54, address@hidden wrote:

Hi Bug-apl,

Currently, at a point in my code I do something like this:

⍝assume the variable 'yadda' exists and is correctly formed, as well as the read_file function
success←yadda ⎕fio[7] tie← 'wr'⎕FIO[3] "yadda.file"
)host ./shellscript.sh yadda.file yadda.file.new
yadda_new← read_file "yadda.file.new"
⍝end of code

My question is: is there either 1. a way to feed )host a variable (I don't think that is possible) or 2. a better way to implement this task in its entirety. I find it a small nuisance that I have to write and then read a file in my code to access non-APL stuff for processing.

-Alex



reply via email to

[Prev in Thread] Current Thread [Next in Thread]