sh.js
sh.js copied to clipboard
Execution inside a child process
Hi,
Firstly I love sh.js, has really helped me out a lot so thank you for writing it!
I have a problem where I have an existing node application using sh.js and I am trying to wrap it up inside of node-mac. The following command correctly returns the string from the command executed when it is not executed inside of the node-mac child process:
sh('promiseutil -C phydrv').result(function(output) {
// Do stuff
});
However, when it is located inside of a node-mac process the output is empty? Am I doing something wrong? Any help would be greatly appreciated.
Thanks.
Hi,
I've never used node-mac, but by looking at your link, I notice that the example service is run as root.
Does promiseutil
print the correct output when you run it as root? Could it be that it relies on something specific to your user (environment variables)?
Cheers
Hi,
If I run promiseutil
on its own (even without root permissions) it executes fine.
The promiseutil
command starts it's own child process so you have to run promiseutil -C <command>
I don't know if that would make a difference?
It works absolutely fine with just sh.js butwhen wrapped in a node-mac service it doesn't output anything.
Thanks
I'm unsure we understand each other.
You're telling me promiseutil
runs fine without root permissions and in a standalone sh.js script. But my question was whether it runs fine when run as root (edit: as node-mac seems to run services as root).
Also, did you compare the environment variables when run on its own and in a node-mac service? On my machine, my user has 67 environment variables set (running env
), whereas root only has 18 (running sudo env
).
Apologies for the delay and mis-understanding.
I can confirm that the command runs fine as root. There are a lot of env
variables missing when running as root also. I am unsure if the promiseutil
command has any dependencies on these though? I'm pretty un-savvy on this issue so is there a way to find the dependencies for a command?
What I suggest you do is add a couple of lines to dump process.env
in your service, run it with node-mac, and then compare the dumped variables with the ones you see when running sudo env
. If some differ (or are missing), export
(/ unset
) the values seen (/ missing) in node-mac in a terminal, run sudo promiseutil ...
. If it fails, then that's a dependency not satisfied.
By the way, does promiseutil rely on being run in a particular directory?
I just updated the package. Could you please update your install?
Hi,
Did you try some of the above? It just occured to me a simple test to try would be to replace your code by:
sh('printf test123').result(function(output) {
// expect output to be 'test123'
});
If output is still empty, there is an issue with sh.js. Otherwise, the problem probably lies elsewhere.
Hi,
I'm really sorry - the machine I need this node app on is currently out of service (probably for another couple of days) so I won't be able to confirm until then. But I will definitely try the printf example so you can potentially close this issue of ASAP. I really appreciate your help!
Thanks
For what it's worth, we ran in to the same issue with promiseutil
not providing the expected (complete) output when we were calling it via python *without a proper shell environment. I wonder @Shepless, did you ever come across a solution to this problem?
*I added "without a proper shell environment", because running our python command via Terminal.app worked as expected.
Fwiw: Root/non-root had no bearing on our results.
Hi Allen,
Thank you for your insight. Unfortunately I don't have Promise hardware so I cannot reproduce the issue. Though I was wondering, could you run the following:
$ promiseutil $WHICHEVER_ARGS_YOU_USE &> /tmp/output.txt < /dev/null
The output and error from promiseutil
will go to /tmp/output.txt
. Have a look and tell us whether the output is complete or buggy. The intent is to test whether promiseutil
supports regular files as standard streams instead of ttys.
I'm also curious did you try calling it from a regular shell script "without a proper shell environment"?
Thanks
HI @guitt
Here's what I get on a system which has no promise attached. (You can probably test this directly by installing their software)
$ promiseutil -C array
===============================================================================
DaId Alias OpStatus CfgCapacity FreeCapacity MaxContiguousCapacity
===============================================================================
No configured disk array in the subsystem
$ promiseutil -C array &> /tmp/output.txt < /dev/null
$ cat /tmp/output.txt
Let me know what else I could do to help with this?
Thanks
Thanks @YesThatAllen ,
I think you have answered your question and @Shepless '.
The first command you've run (promiseutil -C array
) did not require input from the user to produce its output: you didn't need to press any key to make the output table print, did you?
Then the second command is basically the same except it takes input from an empty file (/dev/null
) and writes its output to a regular file (/tmp/output.txt
). It should be able to work this way since there was no interactivity required for the first command. Yet it doesn't (/tmp/output.txt
is empty).
So my guess is that promiseutil
doesn't support files as input and/or output. You can further confirm this by running:
$ promiseutil -C array &> /tmp/output2.txt
$ cat /tmp/output2.txt
$ promiseutil -C array < /dev/null
If output2.txt
is empty and/or the third command produces not output, then promiseutil
cannot be used for non-interactive scripting, be it in Python or Node.