3 Replies Latest reply on Jun 4, 2014 8:00 AM by Yanick Girouard

    How does nexec (w/ nohup) work with Windows?

    Fernando Castro Guti�rrez de Quevedo

      Following the discussion over this thread, I now have issues when trying to execute a nexec with nohup parameter in Windows hosts.


      I have issued a NSH Here console on a Windows machine, run man nexec and seen that the syntax is exactly the same as in a Linux host, i. e. nexec  -nohup hostname "cmd &"

      I also saw here that I should put "cmd /c" before the actual command to avoid this "The system cannot find the file specified.", so all in all the following works fine as far as I can see:


      • nexec -nohup win_machine.corp cmd /c " hostname > /tmp/nh1.txt 2> /tmp/nh2.txt &"
      • nexec -nohup win_machine.corp cmd /c " dir > /tmp/nh1.txt 2> /tmp/nh2.txt &"
      • nexec -nohup win_machine.corp cmd /c " sc query McShield > /tmp/nh1.txt 2> /tmp/nh2.txt &"


      Output gets to C:\tmp\nh1.txt and nh2.txt fine, so that's all right. However, I have been only able to run native Windows commands and not NSH commands which is what I need. They will not work with cmd /c (Says 'ls' is not recognized as an internal or external command, operable program or batch file.),  and nexec altogether will not work without cmd /c.


      Thanks for your help,


        • 1. Re: How does nexec (w/ nohup) work with Windows?
          Yanick Girouard

          The purpose of nexec is to execute remote commands, not NSH commands, which is why you have to call cmd /c (/c means to close the command prompt after the command is executed). All OS need a shell to execute commands. On Linux it's usually bash, and on Windows, it's cmd.exe. If you want all environment variables to be loaded properly for the command you want to run (i.e. system's %PATH% variable), you need to go through the cmd shell to execute commands or you risk having the "The system cannot find the file specified" error.


          All commands passed to nexec are launched remotely on the target, as if someone manually executed it from an interactive remote session. Using -nohup only means that the nexec will call the remote command and return to the script immediately without waiting for it to finish. The command will continue to run on the target and become immune to hangups. Once a nexec -nohup command is launched, you could kill the NSH Script Job and it will continue to run regardless, which can be useful if you're remotely executing a script that could take hours to run and you don't want the connection to timeout and kill the script while it's running.


          NSH commands on the other hand, always run from the application server. NSH is actually a modified zsh shell. If you want to launch a NSH commands immune to hangups, just use nohup


          i.e.: nohup find //target/c/ -name "badfile" -exec rm -f {} \;


          Hope that helps!

          • 2. Re: How does nexec (w/ nohup) work with Windows?
            Fernando Castro Guti�rrez de Quevedo

            Ohh I did not realise that, how silly of me!


            Anyway, thanks for answering this stupid thought ;-) Mondays...