amoffat / sh

Python process launching
https://sh.readthedocs.io/en/latest/
MIT License
6.98k stars 506 forks source link

Special kwarg _cwd and sh.pushd() not working #710

Closed mnwdbase closed 11 months ago

mnwdbase commented 11 months ago

i try:

with sh.pushd("/remote/dir"):
    my_server = sh.ssh.bake("root@1.2.3.4")
    my_server.npm("run")

ERROR: cannot find package.json in /root how can fix?

amoffat commented 11 months ago

sh.pushd only changes the current working directory of your local commands. it doesn't influence sh.ssh's remote cwd. advanced ssh usage is outside of the scope of provided support of this library.

mnwdbase commented 11 months ago

iam only cd, is very simple command, cannot do it?

amoffat commented 11 months ago

Do it on the command line first and you will see it doesn't work like you expect. Once you get it working on the commandline, then convert it to sh

mnwdbase commented 11 months ago

@amoffat i can make ssh root@1.2.3.4 cd /remote/dir && npm run in commandline and works but with sh how can i make it?

amoffat commented 11 months ago

You first need to learn how ssh runs command line arguments on a remote server, then it will become clear to you https://linux.die.net/man/1/ssh

In any case, this is not an sh issue.