Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cygstart equivalent #4287

Closed
ghost opened this issue Jul 9, 2019 · 15 comments
Closed

cygstart equivalent #4287

ghost opened this issue Jul 9, 2019 · 15 comments
Labels

Comments

@ghost
Copy link

ghost commented Jul 9, 2019

With Cygwin, cygstart wraps the ShellExecuteW function

https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutew

cmd.exe has similar option with start and PowerShell with Start-Process

it seems WSL has no such option

@therealkenc
Copy link
Collaborator

$ cat << EOF > wslstart
#!/usr/bin/env sh
cmd.exe /c start \$@
EOF
$ chmod 755 ./wslstart
$ ./wslstart https://github.com/microsoft/WSL/issues/4287

@ghost
Copy link
Author

ghost commented Jul 9, 2019

@therealkenc no, thats not a good idea as it fails with space or ampersand:

wslstart 'http://example.com?aa bb&cc'

@therealkenc
Copy link
Collaborator

therealkenc commented Jul 9, 2019

Alright.

cat << EOF > wslstart
#/usr/bin/env sh
powershell.exe -command \& {Start-Process \'\`echo \$@\`\'}
EOF
$ chmod 755 ./wslstart
$ ./wslstart 'http://example.com?aa bb&cc'

Although that URL mostly has what is coming. Ref #3832 (message) with open LZ #2835.

@0xbadfca11
Copy link

$ ./wslstart iexplore 'http://example.com?aa bb&cc'

Start-Process method can not use any arguments. And -ArgumentList doesn't match the shell's idiom.
After all it is better to use cmd.exe /c start?

cmd.exe /c start '' "$@"

@therealkenc
Copy link
Collaborator

therealkenc commented Jul 9, 2019

I was hoping you'd show.

And -ArgumentList doesn't match the shell's idiom.

Maybe...

#/usr/bin/env sh
al="${@:2}"
al=$(echo "${al/&/\"&\"}" | tr ' ' ,)
if [ $al ]
then
  powershell.exe -command \& {Start-Process \'$(echo $1)\' -ArgumentList $al}
else
  powershell.exe -command \& {Start-Process \'$(echo $1)\'}
fi

After all it is better to use cmd.exe /c start?

Yeah. Probably after all....

#/usr/bin/env sh
cmd.exe /c start '' "${@//&/^&}"

@therealkenc
Copy link
Collaborator

PS: I take back that there's no use case for Linux-native Chrome/Firefox on WSL. Its so all the bash and python scripts in the wild that call xdg-open(1) work out of the box......

@ghost
Copy link
Author

ghost commented Jul 9, 2019

Is this really what you all are suggesting? A hacky shell script? A standalone tool would be better, like cygstart. that way dont have to worry about any drama with cmd.exe or powershell issues.

i was hoping WSL offered something like open or xdg-open, but failing that i found this workaround:

rundll32 url,OpenURL "http://example.com?aa bb&cc"

@therealkenc
Copy link
Collaborator

therealkenc commented Jul 9, 2019

Is this really what you all are suggesting? A hacky shell script?

Your hacky script only launches URLs.

#/usr/bin/env sh
rundll32.exe url,OpenURL "$@"

Which wasn't your OP ask. Your OP ask was for ShellExecute(). So, yes. That's what w'all are suggesting.

@ghost
Copy link
Author

ghost commented Jul 9, 2019

@therealkenc did you actually test that? or are you just assuming after reading the function name?

Works for me with files and URLs

@therealkenc
Copy link
Collaborator

or are you just assuming after reading the function name?

No; I need not assume anything. Because I know what ShellExecuteW() does. And way rundll32 takes parameters.

@ghost
Copy link
Author

ghost commented Jul 9, 2019

@therealkenc perhaps you should actually test it before talking further

it works with URLs and local files

@therealkenc
Copy link
Collaborator

it works with URLs and local files

Yes. Yes it does. Never said it didn't work with both files and URLs. Never even implied otherwise. What I said was I know what ShellExecuteW() does. And that I know why rundll32 takes parameters.

But happy you found an answer to your question either way.

@ghost
Copy link
Author

ghost commented Jul 9, 2019

@therealkenc when you say this:

Never said it didn't work with both files and URLs

I am confused because previously you said this:

Your hacky script only launches URLs.

#4287 (comment)

does that mean something other than what i thought it to mean?

@therealkenc
Copy link
Collaborator

I am confused because previously you said this:

C:\Windows\System32\url.dll will eat path strings and does not insists on the file: prefix. But you already know that, as does everyone less confused. At any rate, happy to hear you found a solution to your use case. Even happier that 0xbadfca11 stepped up with a solution to pushing WSL interop args into start, since it has been a common question and now there is a good answer.

@ghost
Copy link
Author

ghost commented Jul 9, 2019

restoring deleted message:

Apologies for being terse. That on me. url.dll is not strict about URL
syntax. It will parse (eat) the path component string of a file: scheme
without the prefix. It's all good.

https://user-images.githubusercontent.com/7049700/60896072-8b370900-a21a-11e9-91d5-9ad74e9c4900.png

i guess i am a dummy, as I am still not understanding

do you have some example path that gets mangled by url.dll? i know my
workaround is not ideal, but i havent seen any parsing issues myself yet like
i experienced with cmd start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants