Beginner Question: how to run .ijs files from command line?

56 views
Skip to first unread message

Michael Timmers

unread,
Aug 11, 2024, 12:00:07 AMAug 11
to fo...@jsoftware.com
Hello J Software community,
Firstly, I am a beginner to J, as of yesterday. It is great! I think it is really cool.
So here is my probably simple question:
I have been struggling to find a way to run .ijs script files from the command line. Specifically, running them from JQT, since I am using the imagekit package (I have already tried jconsole which doesn’t work with the imagekit package).

So how do people run there script files without having to enter them into the JQT interface each time? I have tried to look, but haven’t found anything yet.

For completeness this is my basic code so far, running version J9.5:

load 'media/imagekit'

NB. must use absolute path
img =: '/Users/michaeltimmers/Desktop/ferrari.jpg'
a =: read_image img
$a

Thanks for any help, it is much appreciated.

kind regards,
Michael

Raul Miller

unread,
Aug 11, 2024, 12:09:53 AMAug 11
to fo...@jsoftware.com
$ echo 'exit echo i.3 3' >test.ijs
$ /c/Other/j9.6/bin/jconsole test.ijs
0 1 2
3 4 5
6 7 8
$

Except you probably have jconsole installed to a different location.

--
Raul
> To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
>

Henry Rich

unread,
Aug 11, 2024, 12:13:05 AMAug 11
to fo...@jsoftware.com

Marcin Żołek

unread,
Aug 11, 2024, 3:14:47 AMAug 11
to fo...@jsoftware.com
More examples and explanations of Imagekit can be found in the Imagekit Addon lab, which is available on Jqt. On the menu select Help > Studio > Labs... > Imagekit Addon.

It is not necessary to specify an absolute path. J can do it, for example:

   jpath '~/Desktop/ferrari.jpg'
/users/marcin/Desktop/ferrari.jpg

Marcin

LdBeth

unread,
Aug 11, 2024, 10:56:21 AMAug 11
to fo...@jsoftware.com
Well for 'media/imagekit' it uses GUI so the JQt is required. jconsole
does not work.

As of j9.6.0-beta16, jqt can read file provided command line
arguments, however jqt would not print output to the terminal stdout.

Assuming you are using a Unix like system, it is possible to work
around that by letting J write output to a named pipe created by mkfifo.

$ mkfifo ~/out
$ jqt ~/test.ijs
$ cat test.ijs
require 'media/imagekit'
require 'format/printf'

img =: jpath '~/test.png'
pip =: jpath '~/out'
a =: read_image img
NB. 5!:_1 is a unexposed foreign function
NB. that print a noun to string the same
NB. way it is printed to terminal
fmt =: 1 80 20 20&(5!:_1)
(fmt a) (1!:2) < pip
exit 0


>>>>> In <CAD2jOU9iN5VKBqS8wOLP7gWW...@mail.gmail.com>
>>>>> Raul Miller <rauld...@gmail.com> wrote:
Raul> $ echo 'exit echo i.3 3' >test.ijs
Raul> $ /c/Other/j9.6/bin/jconsole test.ijs
Raul> 0 1 2
Raul> 3 4 5
Raul> 6 7 8
Raul> $

Raul> Except you probably have jconsole installed to a different location.

> On Sun, Aug 11, 2024 at 12:00 AM Michael Timmers <mic...@timmers.com.au> wrote:
Michael>
Michael> Hello J Software community, Firstly, I am a beginner to J, as
Michael> of yesterday. It is great! I think it is really cool. So
Michael> here is my probably simple question: I have been struggling
Michael> to find a way to run .ijs script files from the command
Michael> line. Specifically, running them from JQT, since I am using
Michael> the imagekit package (I have already tried jconsole which
Michael> doesn’t work with the imagekit package).
Michael>
Michael> So how do people run there script files without having to
Michael> enter them into the JQT interface each time? I have tried to
Michael> look, but haven’t found anything yet.
Michael>
Michael> For completeness this is my basic code so far, running version J9.5:
Michael>
Michael> load 'media/imagekit'
Michael>
Michael> NB. must use absolute path
Michael> img =: '/Users/michaeltimmers/Desktop/ferrari.jpg'
Michael> a =: read_image img
Michael> $a

chris burke

unread,
Aug 11, 2024, 11:22:25 AMAug 11
to fo...@jsoftware.com
Usually, people just load Jqt, open the script and run it. But if you
want to do that from the command line, then try:

1. create a script ferrari.ijs in your J folder, with contents:

load 'media/imagekit'
img =: jpath '~/Desktop/ferrari.jpg'
a =: read_image img

2. run it from a terminal like

~/j9$ bin/jqt ferrari.ijs

3. after the J session opens:

$a
1485 1170 3

Raul Miller

unread,
Aug 11, 2024, 3:06:28 PMAug 11
to fo...@jsoftware.com
Oh, yes... media/imagekit needs jqt instead of jconsole.

Of course, load'media/imagekit' from jconsole will announce that it
needs jqt, and the command line pattern is similar. But... that is
worth calling out.

--
Raul

Joshua Y

unread,
Aug 12, 2024, 3:16:21 AMAug 12
to forum, Michael Timmers
If you want to read an image outside of jqt, you might be better off with `pplatimg`

load 'graphics/pplatimg'
a =: readimg_pplatimg_ 'ferrari.jpg'

This will read the image to an integer matrix that works well with viewmat, but you can easily convert this to an RGB matrix just like imagekit `read_image` gives you

b =: (3 $ 256) #: readimg_pplatimg_ 'ferrari.jpg'
Reply all
Reply to author
Forward
0 new messages