+ Reply to Thread
Results 1 to 4 of 4

Thread: auto-run batch file for Command Prompt shell

  1. #1
    Senior Member
    Join Date
    Aug 2011
    Location
    British Columbia, Canada
    Posts
    383

    auto-run batch file for Command Prompt shell

    I was wondering if it would be possible when one uses Misc > Command Prompt (Shell) for a batch file to be executed when Vedit launches the command prompt?

    In my regular command prompt, I auto execute a batch file that loads doskey, adds my batch file folder to the path, and sets the default directory.

    So the logic would be something like: Check for the existence of cp-shell.bat in the user_home\config and if it is there then execute it when the command prompt opens using the /k parameter for cmd.exe.

    Thank you for any consideration of this idea.

    Scott
    Using Vedit 6.21.3, (32 bit), dated 9/12/11 running on Windows 7 (64 bit).

  2. #2
    Administrator
    Join Date
    Aug 2011
    Location
    Ann Arbor, MI
    Posts
    103
    I'm not aware of a way to specify a batch file to auto-run after a shell out to the command prompt. Perhaps you could always shell out to a batch file and have it include a "cmd.exe /k" to shell out another level.
    The code to implement VEDIT's shell out is very simple and I will entertain any suggestions to it: (Sorry all the extra space got stripped by the forum.)

    /************************************************** ******************************
    * *
    * FUNCTION : EXE() *
    * *
    * PURPOSE : Run Windows program or Command processor for System() command *
    * Shell out using %comspec%, which is typically cmd.exe *
    * *
    * System() - Convert to System("",DOS) *
    * System("prog") - CreateProcess(prog,SW_SHOWNORMAL) *
    * System("prog",MAX) - CreateProcess(prog,SW_SHOWMAXIMIZED) *
    * System("prog",SIMPLE) - CreateProcess(prog,SW_SHOWMINIMIZED) *
    * *
    * System("prog",DOS) - cmd.com /k with SW_NORMAL *
    * System("prog",DOS+MAX) - cmd.com /k with SW_SHOWMAXIMIZED *
    * System("prog",DOS+SIMPLE) - cmd.com /c with SW_SHOWMINIMIZED *
    * System("prog",DOS+DELETE) - cmd.com /c with SW_SHOWMAXIMIZED *
    * *
    * Other Options: O_NOWAIT to hide the "cancel process" dialog box. *
    * *
    * ENTER : sCommand -> string to pass on to cmd.exe, if any. *
    * *
    * RETURN : AX = 0 if program cmd.exe spawned. *
    * = error code otherwise. *
    * *
    ************************************************** ******************************/

    UINT WINAPI EXE( char *sCommand )
    {
    STARTUPINFO sinfo;
    PROCESS_INFORMATION pinfo;
    char CmdLin[ 1028+12+6 ]; //1028 + spares
    //1028 declared in VCONST.ASM
    char *ss;
    UINT uErrCode = 0;
    BOOL bGoodCre;
    BYTE bsaveflg;

    *CmdLin = '\0';
    memset( &sinfo, (BYTE) 0, sizeof(sinfo)); // Zero the structure
    sinfo.cb = sizeof( STARTUPINFO );
    #ifdef WIN32
    sinfo.dwFlags = STARTF_USESHOWWINDOW;
    #else
    sinfo.wShowWindow = SW_SHOWMAXIMIZED;
    #endif

    //
    // If System() or System("prog",DOS) use Command-Processor via %comspec%
    // Note: System() was converted to System("",DOS)
    //
    if (OPTIONS & O_DOS) {
    ss = getenv("comspec");
    if (ss) {
    strcpy(CmdLin,ss);
    } else {
    strcpy(CmdLin,"cmd");
    }
    if (OPTIONS & (O_DELETE | O_SIMPLE) ) { //Auto-close the cmd-box
    strcat(CmdLin," /c ");
    } else {
    strcat(CmdLin," /k "); //Execute and keep cmd-box open
    }
    }
    //
    // Set size of shell window
    //
    if (OPTIONS & O_MAX)
    sinfo.wShowWindow = SW_SHOWMAXIMIZED;
    else if (OPTIONS & O_SIMPLE)
    sinfo.wShowWindow = SW_SHOWMINIMIZED;
    else
    sinfo.wShowWindow = SW_NORMAL;

    //
    // Get command line, if any
    //
    if (sCommand)
    strcat(CmdLin,sCommand);

    //
    // Setup CmdLin[].
    // Set bWait if appropriate.
    //
    bGoodCre = CreateProcess( NULL,
    CmdLin,
    NULL,
    NULL,
    FALSE,
    0,
    NULL,
    NULL,
    &sinfo,
    &pinfo
    );
    if ( bGoodCre ) {
    CloseHandle( pinfo.hThread );
    if ( !(OPTIONS & O_NOWAIT) ) {
    bsaveflg = FCMMODE;
    FCMMODE = FC_WAITTASK;
    WaitProcess( pinfo.hProcess );
    FCMMODE = bsaveflg;
    #if VSIZINT == 8
    RETVAL = 0;
    #endif
    GetExitCodeProcess( pinfo.hProcess, (LPDWORD) &RETVAL );
    }
    CloseHandle( pinfo.hProcess );
    } else
    uErrCode = GetLastError();

    return( uErrCode );

    } // EXE()
    Last edited by mrvedit; July 13th, 2012 at 05:35 PM.

  3. #3
    Senior Member
    Join Date
    Aug 2011
    Location
    British Columbia, Canada
    Posts
    383
    No worries. I thought it might be something easy to do.

    On a windows shortcut for command prompt, I have:

    cmd.exe /k c:\user\owner\batch\wndos.bat

    Thank you for your reply.

    Scott
    Last edited by Scott Lambert; July 14th, 2012 at 12:18 PM.
    Using Vedit 6.21.3, (32 bit), dated 9/12/11 running on Windows 7 (64 bit).

  4. #4
    Senior Member
    Join Date
    Aug 2011
    Location
    British Columbia, Canada
    Posts
    383
    Quote Originally Posted by Scott Lambert View Post
    I was wondering if it would be possible when one uses Misc > Command Prompt (Shell) for a batch file to be executed when Vedit launches the command prompt?
    I figured out how to do the above:

    You create a batch file called wndos.bat :

    @echo off
    rem Command Prompt Setup
    rem Establish Doskey macros
    doskey /listsize=2048 /insert /macrofile=alias.lst
    cls

    You then create an alias list for Doskey called alias.lst :

    cn=cd..$tcd $*
    doc=cd %homedrive%\%homepath%\documents
    m=doskey /macros | more
    pic=cd %homedrive%\%homepath%\pictures
    v=exit
    x=exit
    x86=cd "\program files (x86)"
    \=cd %homedrive%\%homepath%
    ..=cd..

    Then you setup a keystroke macro like so :

    [VISUAL EXIT]system("wndos.bat",dos+nowait)

    Note: you will need to hard code in the full path of both wndos.bat and alias.lst

    Doskey allows you to cycle back thru previous commands without retyping them. The alias list is akin to Vedit's templete editing. To learn more, at the Dos command prompt type: doskey /?

    The wndos.bat can be used for other purposes such as adding your batch directory to the path :

    set path=%path%;c:\batch

    (Environment variables mentioned are for Windows 7, may be different under other versions of windows. Use Set command to see all Env. variables.)

    Maybe I am "old school", but I still find the command prompt and batch files useful.

    Scott
    Using Vedit 6.21.3, (32 bit), dated 9/12/11 running on Windows 7 (64 bit).

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts