Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

This is how to replace cmd.exe

hyperwired
2008-01-04
2013-06-12
  • hyperwired
    hyperwired
    2008-01-04

    ___What Console is and what it isn't___

    Console is like a wrapper for different shells such as cmd.exe and cygwin. Start up console and click on the menu > view > console window and you will get an idea of what is really happening. All Console does is act as a prettier and better INTERFACE to these existing shells/terminals. Console does NOT replace them, since it doesnt really KNOW anything about the commands you are entering; it's just a messenger/middle-man. This knowledge should hopefully allow you to see what is and isnt possible.

    ___making double clicking of .bat files launch Console instead of cmd.exe___
    someone asked this question in Feature Request 1486578 ( http://sourceforge.net/tracker/index.php?func=detail&aid=1486578&group_id=43764&atid=437335 )

    Here is a workaround I discovered:

    A) __simple__

    The bat file is run in console (including all output) but the only problem
    is that the calling directory is not set as the directory, so it only works
    with bat files which use absolute directory references.

    run regedit, browse to this key:

    HKEY_CLASSES_ROOT\batfile\shell\open\command

    change the (Default) value from:

    "%1" %*

    to:

    path_to_console.exe -t cmd -r "/k \"%1\""

    for example, if you installed console to C:\Console2\Console.exe, then you
    would put:

    C:\Console2\Console.exe -t cmd -r "/k \"%1\""

    now note that the "-t cmd" actually refers to a tab profile in Console
    which you must setup:

    start Console: go to settings > tabs > Click "Add" to create a new tab
    name. Call this tab "cmd" (minus the quotes) and put "cmd.exe" (minus
    the quotes) as the shell, leave the starting dir blank.

    B) __hackish__

    This way starts Console up in the same working directory as the clicked file. The downside of this method is that an extra layer of abstraction is created; so a secondary traditional cmd.exe runs in the background.

    make a bat file such as "cns.bat" somewhere (eg. c:\Console2\cns.bat). now put this line in the file:

    C:\Console2\Console.exe -t cmd -r "/k \"%1\"" -d "%CD%"

    Now run regedit, browse to "HKEY_CLASSES_ROOT\batfile\shell\open\command" and change the (Default) value to:

    c:\Console2\cns.bat \"%1\"

    AND THATS IT for method B, *the following are just notes*
    this seems to work; other combinations like regediting the shell open command directly to
    C:\Console2\Console.exe -t cmd -r "/k \"%1\"" -d "%CD%" makes it always start in Console.exe's install directory.
    I've also tried other obscurities like:
    C:\Console2\Console.exe -t cmd -r "/k cd \"%CD%\" && \"%1\""
    set x=%CD% && C:\Console2\Console.exe -t cmd -r "/k cd \"%x%\"\"%1\""
    , but they didnt work :( - maybe you can get it to work? please share :)

    ___making two seperate shortcuts: one for cygwin, one for cmd___

    you dont have to make two seperate Console directories or config .xml files to use.

    Just make different tabs (settings > tabs > Click "Add" to create a new tab); one for cygwin.bat, one for cmd.exe . lets name the tabs 'bash' and 'cmd' respectively. then just edit one shortcut to launch:

    path_to_console.exe -t bash

    and edit the other to launch

    path_to_console.exe -t cmd

    ___alternatives to cmd.exe___

    try cygwin. its the closest thing you will get to having linux on windows at the moment. There is also something called colinux, but its not completely stable yet. There is also something called powershell by microsoft and its basically like cmd.exe on steroids. please note however, that cygwin is like powershell on steroids. Also, from my experience, powershell and cygwin dont mix well.

    Well, I hope this helps. GL HF.

     
    • Open Projects
      Open Projects
      2008-01-12

      >___alternatives to cmd.exe___

      >try cygwin. its the closest thing you will get to having linux on windows at the moment. There is also something called colinux, but its not completely stable yet. There is also something called powershell by microsoft and its basically like cmd.exe on steroids. please note however, that cygwin is like powershell on steroids. Also, from my experience, powershell and cygwin dont mix well.

      Much closer to cmd.exe is 4nt, visit this http://jpsoft.com/4ntdes.htm.
      It is much like closer, because basically all *.bat and *.cmd files could work on it without changes or with minor changes.

       
    • Open Projects
      Open Projects
      2008-01-12

      Sorry, this link should work: http://jpsoft.com/4ntdes.htm

       
    • Mark Baines
      Mark Baines
      2008-01-28

      Just discovered Console.

      Done your A) above and all works nicely until I have a .cmd file with exit at the end. If I double-click on it in Explorer it crashes Console.

      Application popup: Console: Console.exe - Application Error : The instruction at "0x7c57b5f0" referenced memory at "0x00000078". The memory could not be "read".

      Remove the exit command and Console is called, command file runs OK and Console isn't closed, as would be expected.

      System is Win2K SP4.

      Mark B

       
      • Kirill
        Kirill
        2008-02-01

        Mark, hyperwired,

        could you try the following method of ___making double clicking of .bat files launch Console instead of cmd.exe___?

        C) __hackish__without__downside__

        make a bat file such as "cns.bat" somewhere (eg. c:\Console2\cns.bat) and put the following two lines in it:

        @cd %~dp1
        @%1

        :: Commercial AT symbol (@) prevents echo of commands
        :: And double semi-colon is a [faster] equivalent of rem

        Now run regedit, browse to "HKEY_CLASSES_ROOT\batfile\shell\open\command" and change the (Default) value to:

        path_to_console.exe -r "/k short_path_to_cns.bat \"%1\" "

        The above is the exact value that you need to paste into the Edit String dialog of RegEdit. Don't mistake it for the contents of a .reg file.

        The reason to use short_path_to_cns.bat is that I could not make it work if the full path to cns.bat contains spaces. In other words, my cns.bat is located in "C:\docs\user\Local Settings\Temp" (which is my %temp% by the way). So, when I could not get quotes right, I replaced it with "C:\docs\user\LOCALS~1\Temp" which is a short version (and a result of "echo %temp%"). Thus, I have two theories:
        - either I'm very lazy to discover proper way to escape quotes;
        - or path can't contain spaces. period.

        Now as far as I can see, there is only one cmd.exe process. I can't rule out a possibility that there are actually two instances of cmd.exe under one process. Hyperwired, did you actually see two cmd.exe's?

        If my method C) does not work for you and you don't like the downside of the B) method, you can just add

        @cd /d %~dp0

        as the first line of your batch files. For explanations about ~dp, please, see the output of "for /?".

        Also, for those unfortunate, who can't fully control their computers (like my company-provided one), you may be interested to know that you can just create the same hierarchy in HKEY_CURRENT_USER\Software\Classes. In other words, you can create the key

        HKEY_CURRENT_USER\Software\Classes\batfile\shell\open\command

        with the default value above. In general, HKEY_CLASSES_ROOT is shadowed by HKEY_CURRENT_USER\Software\Classes.

        Mark, now to your problems with exit. To test the above, I used the following batch file:

        echo CD: %CD%
        echo First path: %~dp0
        pause
        exit

        And as far as I can tell, it ran in the correct directory. Moreover, it did not crash the Console, but nicely closed the window. It's technically possible that my unofficial build, built with VS2005, does not have the problem, even when Marko's build does. So, feel free to give it a try, visit http://kirill.ca

         
      • Trejkaz
        Trejkaz
        2008-03-26

        If you replace /K with /C and remove the exit, does it do the same thing?

        /C      Carries out the command specified by string and then terminates
        /K      Carries out the command specified by string but remains

        /C would seem to be closer to the normal behaviour when you double-click a .bat file which is launched by cmd.exe as cmd.exe will close after it finishes whether or not there is an exit statement in there.

         
    • Mark Baines
      Mark Baines
      2008-01-28

      Bugger, forgot to say I'm running Console 2.00.138.

      Mark B

       
    • Mark Baines
      Mark Baines
      2008-02-01

      Kirill

      Thanks for that.

      The 'exit' crash is odd. At first it didn't crash and worked well many times.

      After some experimenting, messing with my test batch file, moving cns.cmd it started to crash and now consistently does so, even when I use my original test batch file, which is simply:

      f:
      cd \ cd temporary\temp
      del test.tmp
      exit

      The Console icons remain in my Tray which disappear when I move the mouse over them.

      When I used your unofficial build Console 2.00 Beta, unofficial build 138 I got a crash:
      Application popup: Console: Console.exe - Application Error : The exception unknown software exception (0xc000000d) occurred in the application at location 0x0045a6fc

      When I used your new unofficial highly experimental build 2.0.138.2 I got a crash:
      Application popup: Console: Console.exe - Application Error : The exception unknown software exception (0xc000000d) occurred in the application at location 0x0045be4c.

      It must be Win2K or something else here.

      I can also confirm that there is only the one CMD process when the batch file runs, by the way.

      Mark B

       
  • Everyone
    Everyone
    2010-03-21

    hyperwired, akirill:
    changing the (Default) value from: "%1" %* to: path_to_console.exe -t cmd -r "/k \"%1\"" may fail in the long run when you'll want to launch a batch file with parameters from Win+R box, i.e.

    doMeGood.cmd param1 param2
    

    because you're forgetting the %* parameter which stands for all other parameters, not just the first one which is the name of the batch file,
    so the correct magic spell should be something like this:

    path_to_console.exe -t cmd -r "/k \"%1\" %*"
    

    or

    path_to_console.exe -r "/k short_path_to_cns.bat \"%1\" %*"
    

    I made myself some little au3 scripts that bind cmd's and bat's to a batch run helper that launches them in console.exe window in their own directories and supports parameters. Click, if you're interrested.

     
  • Trig
    Trig
    2012-05-07

    Both methods don't work for me B opens cns.bat then… nothing

    A doesn't open console.exe either.

     
  • fred blom
    fred blom
    2012-12-31

    I can recommend  the au3 scripts 'console tools' by every0n3; it works great!!
    See also my comment on the console tools page.