Page 1 of 4

Shell command fails in LC

Posted: Tue Jul 04, 2017 11:36 pm
by thatkeith
I'm working on a script that 'glues' pairs of pages together in a PDF, so the first two pages are treated as one, the next two as another, and so on. I'm using the pdfjam command-line tool on my Mac, and I have it doing exactly what I want when I run it from Terminal. But when I run the exact same shell script from LiveCode it fails, telling me this: "pdfjam ERROR: can't find pdflatex!"

If I run

Code: Select all

which pdflatex
in Terminal it tells me it's in /Library/TeX/texbin/pdflatex
If I run put

Code: Select all

shell("which pdflatex")
I get nothing.

Any thoughts? :-/

Re: Shell command fails in LC

Posted: Wed Jul 05, 2017 7:11 am
by Thierry
Hi,

Try put shell( "env") and compare with the same in the terminal,
specifically the PATH variable. This should explain why...

HTH,

Thierry

Re: Shell command fails in LC

Posted: Wed Jul 05, 2017 8:38 am
by bogs

Code: Select all

message box shell("env") - 
PATH=/home/bogs/bin:/home/bogs/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:.

terminal [env]
PATH=/home/bogs/bin:/home/bogs/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:.
Not sure I'm seeing the difference, unless this is a mac only thing and I'm on a linux boxen ?

Re: Shell command fails in LC

Posted: Wed Jul 05, 2017 9:55 am
by Thierry
bogs wrote: Not sure I'm seeing the difference, unless this is a mac only thing and I'm on a linux boxen ?
Because you didn't install some extra apps or utilities. (read carefully the OP)

And this is a shell thing!


FYOI, on my box:

Code: Select all

PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/t/bin

and

PATH=/usr/bin:/bin:/usr/sbin:/sbin

Regards,

Thierry

Re: Shell command fails in LC

Posted: Wed Jul 05, 2017 11:36 am
by thatkeith
Thanks Thierry! There is indeed a critical difference:

Message Box:
PATH=/usr/bin:/bin:/usr/sbin:/sbin

Terminal:
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/opt/ImageMagick/bin:/usr/local/MacGPG2/bin:/Library/TeX/texbin:/opt/local/bin

Is there a way to get LC to use these PATH variables?

Going further into uncharted (for me) territory, is there any possible way to have pdflatex be accessible 'self-contained' within an app made with LC? I have this working nicely with the admittedly much simpler exiftool.

Re: Shell command fails in LC

Posted: Wed Jul 05, 2017 12:03 pm
by Thierry
thatkeith wrote:Thanks Thierry! There is indeed a critical difference
Is there a way to get LC to use these PATH variables?
Well, the original problem is that, in terminal you're running your shell script in an interactive mode,
and in LiveCode (not specific to LC by the way) you're running in an non-interactive mode.

One of the differences between these modes, is what startup shell files are executed.

There are few ways to deal with this depending of your context (environment)
and goal ( only on your box, distributing your LC app, ...)

Don't know about pdflatex.

HTH,

Thierry

Re: Shell command fails in LC

Posted: Wed Jul 05, 2017 12:20 pm
by thatkeith
Thierry wrote:There are few ways to deal with this depending of your context (environment)
and goal ( only on your box, distributing your LC app, ...)
Thanks again – I'd love to get this working on my box at the least, as I could then get LC to sort out some of the complications involved in what I'm trying to do.
(It's taking a set of PDF pages, checking that the page count is a clean multiple of 4, using pdftk to shuffle them to a certain print imposition order determined by how many pages there are, then using pdfjam to fuse page pairs together so they print as singles.)

If there's a way to go further so it can run on other systems that would be spectacular! The print room where I teach would dearly love to have this simplified (they'd be open to installing pdflatex if necessary) and it would be great to be able to make something that anyone could use (hence wondering about 'internalising' the command-line tools). BUT just having it function smoothly on my Mac within LC would be very helpful. :)

k

Re: Shell command fails in LC

Posted: Wed Jul 05, 2017 1:10 pm
by Thierry
thatkeith wrote:
Thierry wrote:There are few ways to deal with this depending of your context (environment)
and goal ( only on your box, distributing your LC app, ...)
Thanks again – I'd love to get this working on my box at the least, as I could then get LC to sort out some of the complications involved in what I'm trying to do.
If there's a way to go further so it can run on other systems that would be spectacular! The print room where I teach would dearly love to have this simplified (they'd be open to installing pdflatex if necessary) and it would be great to be able to make something that anyone could use (hence wondering about 'internalising' the command-line tools). BUT just having it function smoothly on my Mac within LC would be very helpful. :)

k
Ok, first stupid thinking.. sometimes they become miracles :)

In your pdflatex installation, do you have a choice for the folder installation,
or is it an absolute filepath?
From this, you might be able to fire your pdflatex with an absolute path....

Thierry

Re: Shell command fails in LC

Posted: Wed Jul 05, 2017 3:02 pm
by thatkeith
I installed pdflatex some months ago in a first attempt at doing this, and I'm afraid I don't remember the installation details! :-/ I did wonder about doing that, but in the pdfjam step there's no inherent way (in my current use) to say anything about where pdflatex might be found. Here's the 'genericised' line that takes a multiple-page PDF and builds them into page pairs:

Code: Select all

/path/to/pdfjam --vanilla /path/to/input.pdf --nup 2x1 --frame true --landscape --outfile /path/to/output.pdf
I'm learning tons through working on this... but I know I'm at the limit of what I can achieve without outside advice! :D

---

As a visual example this:

Code: Select all

________
|      |
|  1   |
|      |
--------
________
|      |
|  2   |
|      |
--------
becomes this:

Code: Select all

_______________
|      |      |
|  1   |  2   |
|      |      |
---------------
The pages have already been shuffled to the 'imposed' running order, so 1, 2, 3, 4, 5, 6, 7, 8 becomes 8, 1, 2, 7, 6, 4, 5. :)

Re: Shell command fails in LC

Posted: Wed Jul 05, 2017 5:03 pm
by Thierry
thatkeith wrote:I installed pdflatex some months ago in a first attempt at doing this, and I'm afraid I don't remember the installation details! :-/ I did wonder about doing that, but in the pdfjam step there's no inherent way (in my current use) to say anything about where pdflatex might be found.
Ok, so shooting a bit in the dark,...

Could you kindly run this and run fast away of your box?

Code: Select all

get  "bash -cl " & quote &  "which pdflatex"  & quote
put last line of  shell( IT)
Still alive?

Regards,

Thierry

Re: Shell command fails in LC

Posted: Wed Jul 05, 2017 6:33 pm
by thatkeith
Heh. Simon Says Clean Environment? Very interesting result!

Code: Select all

/Library/TeX/texbin/pdflatex

Re: Shell command fails in LC

Posted: Wed Jul 05, 2017 6:41 pm
by Thierry
thatkeith wrote:Heh. Simon Says Clean Environment? Very interesting result!

Code: Select all

/Library/TeX/texbin/pdflatex
Great!

So now you know your path...

Regards,

Thierry

Re: Shell command fails in LC

Posted: Wed Jul 05, 2017 6:46 pm
by thatkeith
Very interesting indeed! I tried it out in anger...

Code: Select all

get  "bash -cl " && quote & "/Users/thatkeith/Desktop/pdfjam/bin/pdfjam --vanilla" && theImposedPath && "--nup 2x1 --frame true --landscape --outfile" && theJoinedPath & quote
put shell(it) into field 1
It works. Fabulous! I'm developing a bit of an understanding too, although accent on the "a bit" part. :D

Re: Shell command fails in LC

Posted: Wed Jul 05, 2017 7:00 pm
by thatkeith
I don't suppose it's possible to set the PATH to something by hand – or rather, by script?

Re: Shell command fails in LC

Posted: Wed Jul 05, 2017 7:57 pm
by Thierry
thatkeith wrote:I don't suppose it's possible to set the PATH to something by hand – or rather, by script?
It is !

Sorry, I"m late; see you tomorrow...

Thierry