On Windows 10, I want to show an xterm window on my PC that runs on my server using ssh into the server.
For this I have created a Windows command script, as a file with .cmd extension, with the entire script as:
echo Before time: %TIME%
start /B ssh mysrv "xterm -T mysrv -display mypc:0.0"
echo After time: %TIME%
When running the cmd script through File Explorer, by double clicking on it, it creates the xterm window on my PC. There is no Windows shortcut, or similar, involved. However, a Windows command (cmd) terminal window is also left open, besides the xterm window. Both the messages "Before time:" and "After time:" are show in the Windows terminal window, with a time difference of at most 0.01 s, so they appear immediately.
If I change the xterm
to a command that returns immediately, like date
, or if I entirely remove the line with start ...
, then the script finishes immediately, and no Windows command terminal is left.
I can manually close the Windows command terminal window by clicking the ‘X’, and the xterm window is left open and operational. If I close the xterm window, then the Windows command terminal window is closed automatically.
However, it is rather annoying to get that extra useless Windows command terminal window.
The script is run on a clean Windows 10 installation, where there has been no manual modifications to the registry. For that reason, the suggestions in question I messed with my registry, now I need to change it back have not been attempted.
How can I create a Windows command script that runs the command ssh mysrv …
and then terminates the script,
without leaving the Windows command terminal window open?
exit
command at the end of the script.exit
did not fix the problem; the Windows command terminal window is still left..bat
file should not stay after execution. Please execute the solution in the duplicate link and reboot. If this doesn't help, let me know and I will reinstate your question..bat
extension? (2) Is that the entire script? (3) Are you running it by navigating to the directory where it is and double-clicking on it? Or is it on the Desktop? (4) Is a shortcut involved? (5) What happens if you do the same thing with a.bat
file that contains onlyecho
commands, but nossh
? Or one that runsssh
withoutxterm
, e.g.,ssh mysrv "date >> mylogfile"
? … (Cont’d)echo %TIME%
(case insensitive). (2) It occurs to me now thatssh mysrv "sleep 60"
would be another interesting test — does the CMD window exit immediately, or after a minute? (3) It seems to me that I’ve seen this problem, or something like it, before — the parent CMD window persists because a child process (even one started by thestart
command) is holding a resource (e.g., a network connection) open — but I can’t recall any details. But I see that the question has been reopened, so maybe you’ll get some help now.