Starting GUI programs from WSL using AutoHotKey: how to tell cmd which $DISPLAY variable to use?












1















I have lately found the correct configuration for using Xming to get gvim.exe started from my WSL (Windows Subon Windows, and I wonder if I can automate the procedure. At the end of the day, I would like to replicate the following mapping that fires gvim.exe in WSL together with the parameter. (The short command to issue is gvim +SLoad



#k::
ShellRun("C:vimvim80gvim.exe", "+SLoad", "", "", 3)
return


Step 1: get things to work with cmd.exe



According to the guide to invoke wsl, I should be able to start GUI programs normally, by feeding in the -c flag as follows:



bash -c gvim
# Or, wsl does not need the flag, thus:
wsl gvim


Yet, per the two commands, I get similar error as if I did not set up the $DISPLAY varaible when I was with the WSL comamnd-line.



enter image description here



Step 2: reviewing the correct configuration from WSL



Depending on where the GUI program is fired, one needs to drop the following line to the correct configuration file. For the default bash shell, put it in ~/.bashrc. For Fish shell, put it in ~/.config/fish/config.fish.



# XMing config
export DISPLAY=:0


The value of the $DISPLAY variable is set according to how Xming specifies its own starting parameters. Popping open one that got added to the Start Menu reveals the settings: "C:Program Files (x86)XmingXming.exe" :0 -clipboard -multiwindow.



Question: how may I set up the environmental variables for cmd?










share|improve this question























  • This answer shows how to create a command file which runs each time cmd is started, before any command is executed or prompted for, allowing you to preset any environment variables, among other things.

    – AFH
    Jan 21 at 19:42











  • Try using bash -c "DISPLAY=:0 gvim".

    – harrymc
    Jan 21 at 19:55











  • @harrymc, Amazing! the flag worked great. Could you submit an answer? Let me know if you want me to post it.

    – llinfeng
    Jan 21 at 23:42
















1















I have lately found the correct configuration for using Xming to get gvim.exe started from my WSL (Windows Subon Windows, and I wonder if I can automate the procedure. At the end of the day, I would like to replicate the following mapping that fires gvim.exe in WSL together with the parameter. (The short command to issue is gvim +SLoad



#k::
ShellRun("C:vimvim80gvim.exe", "+SLoad", "", "", 3)
return


Step 1: get things to work with cmd.exe



According to the guide to invoke wsl, I should be able to start GUI programs normally, by feeding in the -c flag as follows:



bash -c gvim
# Or, wsl does not need the flag, thus:
wsl gvim


Yet, per the two commands, I get similar error as if I did not set up the $DISPLAY varaible when I was with the WSL comamnd-line.



enter image description here



Step 2: reviewing the correct configuration from WSL



Depending on where the GUI program is fired, one needs to drop the following line to the correct configuration file. For the default bash shell, put it in ~/.bashrc. For Fish shell, put it in ~/.config/fish/config.fish.



# XMing config
export DISPLAY=:0


The value of the $DISPLAY variable is set according to how Xming specifies its own starting parameters. Popping open one that got added to the Start Menu reveals the settings: "C:Program Files (x86)XmingXming.exe" :0 -clipboard -multiwindow.



Question: how may I set up the environmental variables for cmd?










share|improve this question























  • This answer shows how to create a command file which runs each time cmd is started, before any command is executed or prompted for, allowing you to preset any environment variables, among other things.

    – AFH
    Jan 21 at 19:42











  • Try using bash -c "DISPLAY=:0 gvim".

    – harrymc
    Jan 21 at 19:55











  • @harrymc, Amazing! the flag worked great. Could you submit an answer? Let me know if you want me to post it.

    – llinfeng
    Jan 21 at 23:42














1












1








1








I have lately found the correct configuration for using Xming to get gvim.exe started from my WSL (Windows Subon Windows, and I wonder if I can automate the procedure. At the end of the day, I would like to replicate the following mapping that fires gvim.exe in WSL together with the parameter. (The short command to issue is gvim +SLoad



#k::
ShellRun("C:vimvim80gvim.exe", "+SLoad", "", "", 3)
return


Step 1: get things to work with cmd.exe



According to the guide to invoke wsl, I should be able to start GUI programs normally, by feeding in the -c flag as follows:



bash -c gvim
# Or, wsl does not need the flag, thus:
wsl gvim


Yet, per the two commands, I get similar error as if I did not set up the $DISPLAY varaible when I was with the WSL comamnd-line.



enter image description here



Step 2: reviewing the correct configuration from WSL



Depending on where the GUI program is fired, one needs to drop the following line to the correct configuration file. For the default bash shell, put it in ~/.bashrc. For Fish shell, put it in ~/.config/fish/config.fish.



# XMing config
export DISPLAY=:0


The value of the $DISPLAY variable is set according to how Xming specifies its own starting parameters. Popping open one that got added to the Start Menu reveals the settings: "C:Program Files (x86)XmingXming.exe" :0 -clipboard -multiwindow.



Question: how may I set up the environmental variables for cmd?










share|improve this question














I have lately found the correct configuration for using Xming to get gvim.exe started from my WSL (Windows Subon Windows, and I wonder if I can automate the procedure. At the end of the day, I would like to replicate the following mapping that fires gvim.exe in WSL together with the parameter. (The short command to issue is gvim +SLoad



#k::
ShellRun("C:vimvim80gvim.exe", "+SLoad", "", "", 3)
return


Step 1: get things to work with cmd.exe



According to the guide to invoke wsl, I should be able to start GUI programs normally, by feeding in the -c flag as follows:



bash -c gvim
# Or, wsl does not need the flag, thus:
wsl gvim


Yet, per the two commands, I get similar error as if I did not set up the $DISPLAY varaible when I was with the WSL comamnd-line.



enter image description here



Step 2: reviewing the correct configuration from WSL



Depending on where the GUI program is fired, one needs to drop the following line to the correct configuration file. For the default bash shell, put it in ~/.bashrc. For Fish shell, put it in ~/.config/fish/config.fish.



# XMing config
export DISPLAY=:0


The value of the $DISPLAY variable is set according to how Xming specifies its own starting parameters. Popping open one that got added to the Start Menu reveals the settings: "C:Program Files (x86)XmingXming.exe" :0 -clipboard -multiwindow.



Question: how may I set up the environmental variables for cmd?







command-line bash cmd.exe autohotkey windows-subsystem-for-linux






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 21 at 17:45









llinfengllinfeng

281114




281114













  • This answer shows how to create a command file which runs each time cmd is started, before any command is executed or prompted for, allowing you to preset any environment variables, among other things.

    – AFH
    Jan 21 at 19:42











  • Try using bash -c "DISPLAY=:0 gvim".

    – harrymc
    Jan 21 at 19:55











  • @harrymc, Amazing! the flag worked great. Could you submit an answer? Let me know if you want me to post it.

    – llinfeng
    Jan 21 at 23:42



















  • This answer shows how to create a command file which runs each time cmd is started, before any command is executed or prompted for, allowing you to preset any environment variables, among other things.

    – AFH
    Jan 21 at 19:42











  • Try using bash -c "DISPLAY=:0 gvim".

    – harrymc
    Jan 21 at 19:55











  • @harrymc, Amazing! the flag worked great. Could you submit an answer? Let me know if you want me to post it.

    – llinfeng
    Jan 21 at 23:42

















This answer shows how to create a command file which runs each time cmd is started, before any command is executed or prompted for, allowing you to preset any environment variables, among other things.

– AFH
Jan 21 at 19:42





This answer shows how to create a command file which runs each time cmd is started, before any command is executed or prompted for, allowing you to preset any environment variables, among other things.

– AFH
Jan 21 at 19:42













Try using bash -c "DISPLAY=:0 gvim".

– harrymc
Jan 21 at 19:55





Try using bash -c "DISPLAY=:0 gvim".

– harrymc
Jan 21 at 19:55













@harrymc, Amazing! the flag worked great. Could you submit an answer? Let me know if you want me to post it.

– llinfeng
Jan 21 at 23:42





@harrymc, Amazing! the flag worked great. Could you submit an answer? Let me know if you want me to post it.

– llinfeng
Jan 21 at 23:42










1 Answer
1






active

oldest

votes


















1














To ensure the environment variable is truly passed to the program, use:



bash -c "DISPLAY=:0 gvim"


The shell syntax VARIABLE=VALUE COMMAND sets the environment variable VARIABLE
for the duration of the specified command only. It is roughly equivalent to
(export VARIABLE=VALUE; exec COMMAND).



Displays are numbered from 0, so :0 is the first local display that was started.



Like all environment variables, DISPLAY is inherited from parent process to
child process. However, when started from WSL, there are apparently some glitches.






share|improve this answer
























  • Thanks a lot! I am appending your post with a working version of AHK script, that summons WSL-driven Gvim.

    – llinfeng
    Jan 22 at 14:11











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1396716%2fstarting-gui-programs-from-wsl-using-autohotkey-how-to-tell-cmd-which-display%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














To ensure the environment variable is truly passed to the program, use:



bash -c "DISPLAY=:0 gvim"


The shell syntax VARIABLE=VALUE COMMAND sets the environment variable VARIABLE
for the duration of the specified command only. It is roughly equivalent to
(export VARIABLE=VALUE; exec COMMAND).



Displays are numbered from 0, so :0 is the first local display that was started.



Like all environment variables, DISPLAY is inherited from parent process to
child process. However, when started from WSL, there are apparently some glitches.






share|improve this answer
























  • Thanks a lot! I am appending your post with a working version of AHK script, that summons WSL-driven Gvim.

    – llinfeng
    Jan 22 at 14:11
















1














To ensure the environment variable is truly passed to the program, use:



bash -c "DISPLAY=:0 gvim"


The shell syntax VARIABLE=VALUE COMMAND sets the environment variable VARIABLE
for the duration of the specified command only. It is roughly equivalent to
(export VARIABLE=VALUE; exec COMMAND).



Displays are numbered from 0, so :0 is the first local display that was started.



Like all environment variables, DISPLAY is inherited from parent process to
child process. However, when started from WSL, there are apparently some glitches.






share|improve this answer
























  • Thanks a lot! I am appending your post with a working version of AHK script, that summons WSL-driven Gvim.

    – llinfeng
    Jan 22 at 14:11














1












1








1







To ensure the environment variable is truly passed to the program, use:



bash -c "DISPLAY=:0 gvim"


The shell syntax VARIABLE=VALUE COMMAND sets the environment variable VARIABLE
for the duration of the specified command only. It is roughly equivalent to
(export VARIABLE=VALUE; exec COMMAND).



Displays are numbered from 0, so :0 is the first local display that was started.



Like all environment variables, DISPLAY is inherited from parent process to
child process. However, when started from WSL, there are apparently some glitches.






share|improve this answer













To ensure the environment variable is truly passed to the program, use:



bash -c "DISPLAY=:0 gvim"


The shell syntax VARIABLE=VALUE COMMAND sets the environment variable VARIABLE
for the duration of the specified command only. It is roughly equivalent to
(export VARIABLE=VALUE; exec COMMAND).



Displays are numbered from 0, so :0 is the first local display that was started.



Like all environment variables, DISPLAY is inherited from parent process to
child process. However, when started from WSL, there are apparently some glitches.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 22 at 7:53









harrymcharrymc

260k14271575




260k14271575













  • Thanks a lot! I am appending your post with a working version of AHK script, that summons WSL-driven Gvim.

    – llinfeng
    Jan 22 at 14:11



















  • Thanks a lot! I am appending your post with a working version of AHK script, that summons WSL-driven Gvim.

    – llinfeng
    Jan 22 at 14:11

















Thanks a lot! I am appending your post with a working version of AHK script, that summons WSL-driven Gvim.

– llinfeng
Jan 22 at 14:11





Thanks a lot! I am appending your post with a working version of AHK script, that summons WSL-driven Gvim.

– llinfeng
Jan 22 at 14:11


















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1396716%2fstarting-gui-programs-from-wsl-using-autohotkey-how-to-tell-cmd-which-display%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Plaza Victoria

In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...