Shell script / Python / Node / Newb lost ...

Posted on
Fri Apr 20, 2018 11:55 pm
pmgendon offline
Posts: 35
Joined: Apr 20, 2015

Shell script / Python / Node / Newb lost ...

First. my apologies for posting in this sub, I'm not sure where I should post this.

I'm trying to add indigo support for my PlayStation 4. I can successfully wake the PS4 and launch apps on it with a command line tool called PS4-Waker, for which more info may be found here:https://github.com/dhleong/ps4-waker

It works well from the command line, so I tried converting from command line to shell script. I'm trying to excute the following shell script from the "Run Shell Script" server action:

Code: Select all
#!/bin/bash

/usr/local/bin/ps4-waker -t 30000


The script produces no effect or does not appear to run from indigo. However, if I double click on it in Finder, it will execute the script in Terminal and will generate the desired outcome.

It would still not work if I removed the -t 30000 (default is -t 10000.

I tried enabling the "Store the output of the script in a variable, but I'm getting the following error when I execute the action with the checkbox checked:

Action Collection Error Script /Users/myriam/Documents/Indigo-Scripts/ps4Waker-wake exited abnormally with a return code of: 127


after some more research, I stumbled on this thread http://forums.indigodomo.com/viewtopic.php?f=107&t=12148

So I decided to switch to Python to see if I would have better results

here's the python code:

Code: Select all
import subprocess

command = "/usr/local/bin/ps4-waker"
arg = "standby"

proc = subprocess.Popen([command, '-t 30000', arg], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

out, err = proc.communicate()

indigo.server.log(u"command error: %s" % err)


here's the error that's logged in console:

command error: env: node: No such file or directory


Any idea as to what I should do to get it to work?

Posted on
Sat Apr 21, 2018 1:47 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Shell script / Python / Node / Newb lost ...

Ill have a look when I get downstairs, but additionally the source code for PS4-Waker is on GitHub in .js code - it wouldn’t take too long to turn that into full python code or a plugin.


Sent from my iPhone using Tapatalk Pro

Posted on
Sat Apr 21, 2018 8:32 am
pmgendon offline
Posts: 35
Joined: Apr 20, 2015

Re: Shell script / Python / Node / Newb lost ...

howartp wrote:
Ill have a look when I get downstairs, but additionally the source code for PS4-Waker is on GitHub in .js code - it wouldn’t take too long to turn that into full python code or a plugin.


Sent from my iPhone using Tapatalk Pro


That would be awesome! As you can tell, I’m not that good at scripting. I have a lot of ideas, but lack the knowledge to implement them!

Thanks for your time and your help!


Sent from my iPhone using Tapatalk

Posted on
Sat Apr 21, 2018 11:37 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Shell script / Python / Node / Newb lost ...

Right, forget what I said about making it into a plugin or raw python - I hadn't realised it called libraries up and down the github tree. It looked like a one page script that at first glance looks perfectly doable.

So, onto calling the process in Python.

Code: Select all
import subprocess

command = "/usr/local/bin/ps4-waker standby -t 30000"

proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

out, err = proc.communicate()

indigo.server.log(u"command error: %s" % err)

See how that goes for starters.

With Popen, you either ["put", "arguments", "together"] in a list as shown, OR you "put them together" and set Shell=True.

You had done both which won't have helped things.

Peter

Posted on
Sun Apr 22, 2018 8:18 pm
pmgendon offline
Posts: 35
Joined: Apr 20, 2015

Re: Shell script / Python / Node / Newb lost ...

howartp wrote:
Right, forget what I said about making it into a plugin or raw python - I hadn't realised it called libraries up and down the github tree. It looked like a one page script that at first glance looks perfectly doable.

So, onto calling the process in Python.

Code: Select all
import subprocess

command = "/usr/local/bin/ps4-waker standby -t 30000"

proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

out, err = proc.communicate()

indigo.server.log(u"command error: %s" % err)

See how that goes for starters.

With Popen, you either ["put", "arguments", "together"] in a list as shown, OR you "put them together" and set Shell=True.

You had done both which won't have helped things.

Peter


Thank you for the precisions!

I have updated the code and this is the error I'm now having

Script command error: env: node: No such file or directory

Posted on
Mon Apr 23, 2018 3:49 am
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Shell script / Python / Node / Newb lost ...

Try changing this line:
Code: Select all
command = "/usr/local/bin/ps4-waker standby -t 30000"

To this:
Code: Select all
command = "//usr/local/bin/ps4-waker standby -t 30000"

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Apr 23, 2018 4:46 am
pmgendon offline
Posts: 35
Joined: Apr 20, 2015

Re: Shell script / Python / Node / Newb lost ...

DaveL17 wrote:
Try changing this line:
Code: Select all
command = "/usr/local/bin/ps4-waker standby -t 30000"

To this:
Code: Select all
command = "//usr/local/bin/ps4-waker standby -t 30000"


thank you for the suggestion. I'm still getting the command error: env: node: No such file or directory error.

Posted on
Mon Apr 23, 2018 5:52 am
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Shell script / Python / Node / Newb lost ...

What do you get when you the following script?
Code: Select all
import glob
files = glob.glob("/usr/local/bin/ps4-waker*")
indigo.server.log(unicode(files))

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Apr 23, 2018 5:52 am
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Shell script / Python / Node / Newb lost ...

Duplicate post removed.
Last edited by DaveL17 on Mon Apr 23, 2018 8:19 pm, edited 1 time in total.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Apr 23, 2018 8:04 pm
pmgendon offline
Posts: 35
Joined: Apr 20, 2015

Re: Shell script / Python / Node / Newb lost ...

DaveL17 wrote:
DaveL17 wrote:
What do you get when you run the following script?
Code: Select all
import glob
files = glob.glob("/usr/local/bin/ps4-waker*")
indigo.server.log(unicode(files))


Hey Dave,

Thank you for your help with my code!

Ran the script with a slight modification as I had unistalled node to reinstall it in the non-administrator user on which indigo runs. This is the code I ran:

Code: Select all
import glob
files = glob.glob("/Users/myriam/.nvm/versions/node/v9.11.1/bin/ps4-waker*")
indigo.server.log(unicode(files))


here's the result

Script ['/Users/myriam/.nvm/versions/node/v9.11.1/bin/ps4-waker']


I then tried adding import glob at the top of my other script, but I'm still having the following error:

Script command error: env: node: No such file or directory

Posted on
Mon Apr 23, 2018 8:19 pm
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Shell script / Python / Node / Newb lost ...

Heh. I'm not sure how I quoted myself up there, but I'll have to fix that.

The reason I asked you to run the script with glob is to see exactly how the command file would appear and that the script had the authority to see it. glob would have no effect on your script's ability to run.

How about this one:
Code: Select all
import subprocess

command = "/Users/myriam/.nvm/versions/node/v9.11.1/bin/ps4-waker standby -t 30000"

proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

out, err = proc.communicate()

indigo.server.log(u"command error: %s" % err)


Alternatively, if the above doesn't work, what about this:
Code: Select all
import subprocess

command = ["/Users/myriam/.nvm/versions/node/v9.11.1/bin/ps4-waker", "standby", "-t", "30000"]

proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

out, err = proc.communicate()

indigo.server.log(u"command error: %s" % err)

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Apr 23, 2018 8:31 pm
pmgendon offline
Posts: 35
Joined: Apr 20, 2015

Re: Shell script / Python / Node / Newb lost ...

DaveL17 wrote:
Heh. I'm not sure how I quoted myself up there, but I'll have to fix that.

The reason I asked you to run the script with glob is to see exactly how the command file would appear and that the script had the authority to see it. glob would have no effect on your script's ability to run.

How about this one:
Code: Select all
import subprocess

command = "/Users/myriam/.nvm/versions/node/v9.11.1/bin/ps4-waker standby -t 30000"

proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

out, err = proc.communicate()

indigo.server.log(u"command error: %s" % err)


Alternatively, if the above doesn't work, what about this:
Code: Select all
import subprocess

command = ["/Users/myriam/.nvm/versions/node/v9.11.1/bin/ps4-waker", "standby", "-t", "30000"]

proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

out, err = proc.communicate()

indigo.server.log(u"command error: %s" % err)


I tried both codes and I'm still having the same error. It's as if Indigo does not have access to node for some reason....

Posted on
Mon Apr 23, 2018 8:43 pm
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Shell script / Python / Node / Newb lost ...

Did you run the glob script above from an Indigo scripting window or from Terminal?

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Apr 23, 2018 8:48 pm
pmgendon offline
Posts: 35
Joined: Apr 20, 2015

Re: Shell script / Python / Node / Newb lost ...

From an indigo scripting window.


Sent from my iPhone using Tapatalk

Posted on
Mon Apr 23, 2018 8:59 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Shell script / Python / Node / Newb lost ...

From googling, whilst still learning bash etc.....

The shebang line in ps4walker is calling “env node”.

Subprocess.Popen() has an env parameter.

Does adding env=node to the Popen Command help?

I’m on iPhone here so not gonna attempt to update the code line for you!


Sent from my iPhone using Tapatalk Pro

Who is online

Users browsing this forum: No registered users and 3 guests