Cygwin's bash can't run 'net use /user' command?

狂风中的少年 提交于 2020-01-24 06:21:11

问题


I run 'net use /user:"Someone" \somewhere', and it works well with cmd.exe.

With the same cmd.exe, run 'bash --login -i' to use the cygwin/bash, and run the same command but I get the error message as follows.

System error 67 has occurred.

The network name cannot be found.

Why can't I run 'net use /user' command with cygwin/bash?


回答1:


In cygwin's bash, you need to escape any of those forwardback slashes, as those are interpreted as escape characters.

try this

net use /user:"Someone" \\\\server\\share

or use single quotes, which will pass the argument unchanged

net use /user:"Someone" '\\server\share'




回答2:


I have ran into problems attempting to use the /delete switch with net use from bash in windows. It seems to be something with the way certain windows commands process command line arguments.

I thought I could get around it by launching "net use" from a cmd.exe sub shell, but that too appears to be impacted by the argument processing problem. I found a work around for cmd.exe in quoting but could not seem to find the right quoting to use net use directly for the task.

$ cmd "/c net use T: /delete"



回答3:


In MSYS/Git Bash, parameters starting with a forward slash are converted by POSIX-to-Windows path conversion
(i.e. /delete looks like a path and is converted to C:\Program Files\Git\delete or something alike).

There are two solutions to circumvent this conversion:

  1. Double the first slash to avoid POSIX-to-Windows conversion:

    net use //user
    # outputs usage of NET USE
    
    net use T: //delete
    # outputs "T: was deleted successfully."
    
  2. Use temporary environment variable MSYS_NO_PATHCONV=1 like so:

    MSYS_NO_PATHCONV=1 net use /user
    # outputs usage of NET USE
    
    MSYS_NO_PATHCONV=1 net use T: /delete
    # outputs "T: was deleted successfully."
    

Source/Explanation: Bash translates path parameter in Unix format to windows format, need a way to suppress it #577

Update: Mention MSYS is used for this answer as suggested in comment from bobbogo.



来源:https://stackoverflow.com/questions/2238935/cygwins-bash-cant-run-net-use-user-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!