How can I make a Windows shortcut that launches Bash and runs commands?
I've created a windows shortcut with a target that looks like
"C:WindowsSystem32bash.exe" php /c/script.php
(I know I could just use my windows verison of php cli to run this, but out of curiosity)
When I click my shortcut it just pops open a cmd window and closes (where the script should take minutes to run.
Is there a way to pipe commands to bash.exe on windows?
windows bash cmd.exe shortcuts windows-subsystem-for-linux
New contributor
add a comment |
I've created a windows shortcut with a target that looks like
"C:WindowsSystem32bash.exe" php /c/script.php
(I know I could just use my windows verison of php cli to run this, but out of curiosity)
When I click my shortcut it just pops open a cmd window and closes (where the script should take minutes to run.
Is there a way to pipe commands to bash.exe on windows?
windows bash cmd.exe shortcuts windows-subsystem-for-linux
New contributor
It's simple, just wait and hello world, so i should see something. But the cmd window pops open for a moment and closes.
– Keith
13 hours ago
1
Many things I see that are odd about this question. If it were WSL, then "/c/script.php" would be "/mnt/c/script.php".. it it were CYGWIN or MINGW, then bash.exe wouldn't be in Windows/System32. What 'Unix' are you using?
– Señor CMasMas
13 hours ago
add a comment |
I've created a windows shortcut with a target that looks like
"C:WindowsSystem32bash.exe" php /c/script.php
(I know I could just use my windows verison of php cli to run this, but out of curiosity)
When I click my shortcut it just pops open a cmd window and closes (where the script should take minutes to run.
Is there a way to pipe commands to bash.exe on windows?
windows bash cmd.exe shortcuts windows-subsystem-for-linux
New contributor
I've created a windows shortcut with a target that looks like
"C:WindowsSystem32bash.exe" php /c/script.php
(I know I could just use my windows verison of php cli to run this, but out of curiosity)
When I click my shortcut it just pops open a cmd window and closes (where the script should take minutes to run.
Is there a way to pipe commands to bash.exe on windows?
windows bash cmd.exe shortcuts windows-subsystem-for-linux
windows bash cmd.exe shortcuts windows-subsystem-for-linux
New contributor
New contributor
New contributor
asked 13 hours ago
KeithKeith
1134
1134
New contributor
New contributor
It's simple, just wait and hello world, so i should see something. But the cmd window pops open for a moment and closes.
– Keith
13 hours ago
1
Many things I see that are odd about this question. If it were WSL, then "/c/script.php" would be "/mnt/c/script.php".. it it were CYGWIN or MINGW, then bash.exe wouldn't be in Windows/System32. What 'Unix' are you using?
– Señor CMasMas
13 hours ago
add a comment |
It's simple, just wait and hello world, so i should see something. But the cmd window pops open for a moment and closes.
– Keith
13 hours ago
1
Many things I see that are odd about this question. If it were WSL, then "/c/script.php" would be "/mnt/c/script.php".. it it were CYGWIN or MINGW, then bash.exe wouldn't be in Windows/System32. What 'Unix' are you using?
– Señor CMasMas
13 hours ago
It's simple, just wait and hello world, so i should see something. But the cmd window pops open for a moment and closes.
– Keith
13 hours ago
It's simple, just wait and hello world, so i should see something. But the cmd window pops open for a moment and closes.
– Keith
13 hours ago
1
1
Many things I see that are odd about this question. If it were WSL, then "/c/script.php" would be "/mnt/c/script.php".. it it were CYGWIN or MINGW, then bash.exe wouldn't be in Windows/System32. What 'Unix' are you using?
– Señor CMasMas
13 hours ago
Many things I see that are odd about this question. If it were WSL, then "/c/script.php" would be "/mnt/c/script.php".. it it were CYGWIN or MINGW, then bash.exe wouldn't be in Windows/System32. What 'Unix' are you using?
– Señor CMasMas
13 hours ago
add a comment |
2 Answers
2
active
oldest
votes
First of all, bash.exe has been deprecated. You should use wsl.exe
in command lines. Use Windows Insiders Builds 17063 and above for the interoperability feature in WSL. For your case, both of this may work:
wsl.exe php /mnt/c/MyFiles/test.php
wsl.exe --exec php /mnt/c/MyFiles/test.php
Here is the wsl.exe
usage information:
Usage: wsl.exe [Argument] [Options...] [CommandLine]
Arguments to run Linux binaries:
If no command line is provided, wsl.exe launches the default shell.
--exec, -e <CommandLine>
Execute the specified command without using the default Linux shell.
--
Pass the remaining command line as is.
For further details, read WSL interoperabiltity with Windows.
Thank you for the heads up about bash.exe's deprecation. I'll use wsl from here on out. And your example worked perfectly, thank you!
– Keith
11 hours ago
add a comment |
If this is WSL, use bash.exe -c "command to run" as in
C:WindowsSystem32bash.exe -c "vi ~/.bashrc"
or
C:WindowsSystem32bash.exe -c "php /mnt/c/script.php"
Thank you! The-c
argument worked great. It was tough to choose which one to accept as answer as they're both great.
– Keith
11 hours ago
Yes I'm aware. afaik I can only accept one answer.
– Keith
11 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Keith is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1413721%2fhow-can-i-make-a-windows-shortcut-that-launches-bash-and-runs-commands%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
First of all, bash.exe has been deprecated. You should use wsl.exe
in command lines. Use Windows Insiders Builds 17063 and above for the interoperability feature in WSL. For your case, both of this may work:
wsl.exe php /mnt/c/MyFiles/test.php
wsl.exe --exec php /mnt/c/MyFiles/test.php
Here is the wsl.exe
usage information:
Usage: wsl.exe [Argument] [Options...] [CommandLine]
Arguments to run Linux binaries:
If no command line is provided, wsl.exe launches the default shell.
--exec, -e <CommandLine>
Execute the specified command without using the default Linux shell.
--
Pass the remaining command line as is.
For further details, read WSL interoperabiltity with Windows.
Thank you for the heads up about bash.exe's deprecation. I'll use wsl from here on out. And your example worked perfectly, thank you!
– Keith
11 hours ago
add a comment |
First of all, bash.exe has been deprecated. You should use wsl.exe
in command lines. Use Windows Insiders Builds 17063 and above for the interoperability feature in WSL. For your case, both of this may work:
wsl.exe php /mnt/c/MyFiles/test.php
wsl.exe --exec php /mnt/c/MyFiles/test.php
Here is the wsl.exe
usage information:
Usage: wsl.exe [Argument] [Options...] [CommandLine]
Arguments to run Linux binaries:
If no command line is provided, wsl.exe launches the default shell.
--exec, -e <CommandLine>
Execute the specified command without using the default Linux shell.
--
Pass the remaining command line as is.
For further details, read WSL interoperabiltity with Windows.
Thank you for the heads up about bash.exe's deprecation. I'll use wsl from here on out. And your example worked perfectly, thank you!
– Keith
11 hours ago
add a comment |
First of all, bash.exe has been deprecated. You should use wsl.exe
in command lines. Use Windows Insiders Builds 17063 and above for the interoperability feature in WSL. For your case, both of this may work:
wsl.exe php /mnt/c/MyFiles/test.php
wsl.exe --exec php /mnt/c/MyFiles/test.php
Here is the wsl.exe
usage information:
Usage: wsl.exe [Argument] [Options...] [CommandLine]
Arguments to run Linux binaries:
If no command line is provided, wsl.exe launches the default shell.
--exec, -e <CommandLine>
Execute the specified command without using the default Linux shell.
--
Pass the remaining command line as is.
For further details, read WSL interoperabiltity with Windows.
First of all, bash.exe has been deprecated. You should use wsl.exe
in command lines. Use Windows Insiders Builds 17063 and above for the interoperability feature in WSL. For your case, both of this may work:
wsl.exe php /mnt/c/MyFiles/test.php
wsl.exe --exec php /mnt/c/MyFiles/test.php
Here is the wsl.exe
usage information:
Usage: wsl.exe [Argument] [Options...] [CommandLine]
Arguments to run Linux binaries:
If no command line is provided, wsl.exe launches the default shell.
--exec, -e <CommandLine>
Execute the specified command without using the default Linux shell.
--
Pass the remaining command line as is.
For further details, read WSL interoperabiltity with Windows.
answered 12 hours ago
BiswapriyoBiswapriyo
3,25141344
3,25141344
Thank you for the heads up about bash.exe's deprecation. I'll use wsl from here on out. And your example worked perfectly, thank you!
– Keith
11 hours ago
add a comment |
Thank you for the heads up about bash.exe's deprecation. I'll use wsl from here on out. And your example worked perfectly, thank you!
– Keith
11 hours ago
Thank you for the heads up about bash.exe's deprecation. I'll use wsl from here on out. And your example worked perfectly, thank you!
– Keith
11 hours ago
Thank you for the heads up about bash.exe's deprecation. I'll use wsl from here on out. And your example worked perfectly, thank you!
– Keith
11 hours ago
add a comment |
If this is WSL, use bash.exe -c "command to run" as in
C:WindowsSystem32bash.exe -c "vi ~/.bashrc"
or
C:WindowsSystem32bash.exe -c "php /mnt/c/script.php"
Thank you! The-c
argument worked great. It was tough to choose which one to accept as answer as they're both great.
– Keith
11 hours ago
Yes I'm aware. afaik I can only accept one answer.
– Keith
11 hours ago
add a comment |
If this is WSL, use bash.exe -c "command to run" as in
C:WindowsSystem32bash.exe -c "vi ~/.bashrc"
or
C:WindowsSystem32bash.exe -c "php /mnt/c/script.php"
Thank you! The-c
argument worked great. It was tough to choose which one to accept as answer as they're both great.
– Keith
11 hours ago
Yes I'm aware. afaik I can only accept one answer.
– Keith
11 hours ago
add a comment |
If this is WSL, use bash.exe -c "command to run" as in
C:WindowsSystem32bash.exe -c "vi ~/.bashrc"
or
C:WindowsSystem32bash.exe -c "php /mnt/c/script.php"
If this is WSL, use bash.exe -c "command to run" as in
C:WindowsSystem32bash.exe -c "vi ~/.bashrc"
or
C:WindowsSystem32bash.exe -c "php /mnt/c/script.php"
answered 13 hours ago
Señor CMasMasSeñor CMasMas
1716
1716
Thank you! The-c
argument worked great. It was tough to choose which one to accept as answer as they're both great.
– Keith
11 hours ago
Yes I'm aware. afaik I can only accept one answer.
– Keith
11 hours ago
add a comment |
Thank you! The-c
argument worked great. It was tough to choose which one to accept as answer as they're both great.
– Keith
11 hours ago
Yes I'm aware. afaik I can only accept one answer.
– Keith
11 hours ago
Thank you! The
-c
argument worked great. It was tough to choose which one to accept as answer as they're both great.– Keith
11 hours ago
Thank you! The
-c
argument worked great. It was tough to choose which one to accept as answer as they're both great.– Keith
11 hours ago
Yes I'm aware. afaik I can only accept one answer.
– Keith
11 hours ago
Yes I'm aware. afaik I can only accept one answer.
– Keith
11 hours ago
add a comment |
Keith is a new contributor. Be nice, and check out our Code of Conduct.
Keith is a new contributor. Be nice, and check out our Code of Conduct.
Keith is a new contributor. Be nice, and check out our Code of Conduct.
Keith is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1413721%2fhow-can-i-make-a-windows-shortcut-that-launches-bash-and-runs-commands%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It's simple, just wait and hello world, so i should see something. But the cmd window pops open for a moment and closes.
– Keith
13 hours ago
1
Many things I see that are odd about this question. If it were WSL, then "/c/script.php" would be "/mnt/c/script.php".. it it were CYGWIN or MINGW, then bash.exe wouldn't be in Windows/System32. What 'Unix' are you using?
– Señor CMasMas
13 hours ago