14 Replies
      Latest reply on Sep 27, 2019 1:55 AM by SyamalaDutt
      SyamalaDutt Level 1 Level 1 (0 points)

        I am trying to stop a nodejs server started using forever using below code:

         

         

             func shell(command: String) -> Int32 {

                    let task = Process()

                    task.launchPath = "/usr/bin/env"

                    task.arguments = ["sh", "-c", command]

                    task.launch()

                    task.waitUntilExit()

                    return task.terminationStatus

                }

        shell(command: "$forever_PATH/forever stop node.js")

         

         

        I am seeing below error

         

         

            env: node: No such file or directory

         

         

        PS:node is located in /usr/local/bin

        • Re: How to run a node from swift
          eskimo Apple Staff Apple Staff (12,265 points)

          I am trying to stop a nodejs server started using forever

          What platform are you working on?

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

          • Re: How to run a node from swift
            SyamalaDutt Level 1 Level 1 (0 points)

            I am working on Mojave MacOS.

              • Re: How to run a node from swift
                eskimo Apple Staff Apple Staff (12,265 points)

                OK.

                There are a lot of connected parts here, and I recommend that you try teasing them apart to see whether things start going wrong:

                1. First try running a simple command-line tool using Process.  My preferred tool for this sort of thing is /bin/echo.

                2. Next, try extending that to Node itself.

                3. Finally, rope in forever.

                Share and Enjoy

                Quinn “The Eskimo!”
                Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                let myEmail = "eskimo" + "1" + "@apple.com"

                  • Re: How to run a node from swift
                    SyamalaDutt Level 1 Level 1 (0 points)

                    I tries /bin/ls. It is printing list of files but when i run forever it throws error

                      • Re: How to run a node from swift
                        eskimo Apple Staff Apple Staff (12,265 points)

                        What about that intermediate step, running Node without forever?

                        Share and Enjoy

                        Quinn “The Eskimo!”
                        Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                        let myEmail = "eskimo" + "1" + "@apple.com"

                          • Re: How to run a node from swift
                            SyamalaDutt Level 1 Level 1 (0 points)

                            Sorry, i missed intermediate step. running node throws me below error

                             

                            sh: /usr/local/bin/node: Operation not permitted

                              • Re: How to run a node from swift
                                eskimo Apple Staff Apple Staff (12,265 points)

                                running node throws me below error

                                OK, that’s not good.

                                OK, next question: Is your app sandboxed?

                                Share and Enjoy

                                Quinn “The Eskimo!”
                                Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                                let myEmail = "eskimo" + "1" + "@apple.com"

                                  • Re: How to run a node from swift
                                    SyamalaDutt Level 1 Level 1 (0 points)

                                    My App is not sandboxed !!

                                      • Re: How to run a node from swift
                                        eskimo Apple Staff Apple Staff (12,265 points)

                                        My App is not sandboxed !!

                                        Hmmmm, that rules out the most common cause of EPERM errors (which is what Operation not permitted translates to).  Beyond that, I’ve no good idea as to what’s triggering this error.

                                        It looks like this error is being reported by sh, indicating that it can’t invoke /usr/local/bin/node.  Are you sure that /usr/local/bin/node is the right path?  And that there’s a runnable copy of node there?

                                        Share and Enjoy

                                        Quinn “The Eskimo!”
                                        Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                                        let myEmail = "eskimo" + "1" + "@apple.com"

                                          • Re: How to run a node from swift
                                            SyamalaDutt Level 1 Level 1 (0 points)

                                            Yes i have it there

                                            ls -la /usr/local/bin/node

                                            -rwxr-xr-x  1 root  wheel  41796640 Sep  4 21:55 /usr/local/bin/node

                                             

                                             

                                            Is it some access related issue caused in mojave due to full disc access or something ?

                                              • Re: How to run a node from swift
                                                eskimo Apple Staff Apple Staff (12,265 points)

                                                Is it some access related issue caused in mojave due to full disc access or something ?

                                                /usr/local/ does not have any special protection in that regard.  You might run into problem if your app is sandboxed, but you assure me that’s not the case.

                                                Just for grins I made a copy of /bin/echo, signed it myself, and installed it as /usr/local/bin/qecho.  I was then able to run it like so:

                                                NSLog("will launch")
                                                let p = Process()
                                                p.launchPath = "/usr/local/bin/qecho"
                                                p.arguments = ["Hello", "Cruel", "World!"]
                                                p.terminationHandler = { _ in
                                                    NSLog("did terminate")
                                                }
                                                p.launch()
                                                NSLog("did launch")

                                                This is on 10.14.6.

                                                It looks like you’re running node via sh.  What happens if you run it directly?

                                                Share and Enjoy

                                                Quinn “The Eskimo!”
                                                Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                                                let myEmail = "eskimo" + "1" + "@apple.com"