ExecProg not performing as expected.

Product Compare Forums Multi-Edit Support ExecProg not performing as expected.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
  • #2976

    I am attempting to call a dir command, and find that the only result in the file is not what appears if the command is executed on the command line.

    Here is my code:
    [code:2ixcwnf2]void Test
    int Flags, DOS_result;
    str DirStr = "C:\\text\\Analysis.txt";
    str FileStr = "Z:\\DLCS_core\\R0230\\analysis"; // mapped drive
    str FileList;
    // dir FileStr > DirStr
    //MsgDlg (FileStr, "Status", "", 1);
    FileList = ‘dir ‘+FileStr+’ > ‘+DirStr;
    Flags = _EP_Flags_ExeDos | _EP_FLAGS_COMSPEC | _EP_FLAGS_NORMAL; // Run as a Dos program
    DOS_result = ExecProg( FileList, ”, ”, ”, Flags );
    if(DOS_result == 0)
    MsgDlg ("DOS_result is " + str(DOS_result)+ " " +FileList, "Status", "", 1);
    MsgDlg ("DOS_result is " + str(DOS_result), "Error", "", 1);


    If I run this as is, the output that I get is:

    C:\Program Files\Multi-Edit 2008>"dir /X"

    Following is a snippet of the actual command line:
    12/31/2013 09:41 AM 595 analysis_2955.xml
    12/31/2013 09:41 AM 26,857 analysis_2956.xml
    12/31/2013 09:41 AM 324 analysis_2977.xml
    12/31/2013 09:41 AM 3,053 analysis_24283.xml
    12/31/2013 09:41 AM 11,245 analysis_25287.xml
    12/31/2013 09:41 AM 325 analysis_26062.xml
    12/31/2013 09:41 AM 3,806 analysis_26080.xml
    12/31/2013 09:41 AM 295 analysis_26081.xml
    12/31/2013 09:41 AM 4,704 analysis_29719.xml

    This is MEW 11.04 running on Windows 7 Professional 32 bit.

    Clay Martin

    Are you indicating that the file:
    C:\Program Files\Multi-Edit 2008>"dir /X"
    after execution?

    Here is the prototype for the call
    int ExecProg(
    str Prog, // = Parse_Str("/PROG=", Mparm_Str),
    // The command line
    str Working_Dir, // Parse_Str("/WD=",Mparm_Str),
    str StdOut_File, // = Parse_Str("/RED=", Mparm_Str),
    // The filename to output STDOUT to
    // (DOS .EXE files only)
    str StdErr_File, // = Parse_Str("/REDERR=", Mparm_Str),
    // The filename to output STDERR to
    // (DOS .EXE files only)
    int Flags // = Parse_Int("/FLAGS=", Mparm_Str )
    // Flags; see #define _EP_FLAGS_xxxx above

    Instead of the redirect have you tried passing the output file to the call in the 3rd parameter? You might also try passing the directory you want a list of in the working dir parm. You might also try just using only one of _EP_Flags_ExeDos or _EP_FLAGS_COMSPEC at a time.



    Clay, At one point, I had to create a C:\bat\dir.bat file with "dir /X" in it, and then set the environment path to include C:/bat.

    I found out that this is where the dir /X came from. I then put the working directory into the working dir parm, and the output file in the stdout parm, and now end up with "Z:\DLCS_core\R0230\analysis>"dir /X"

    Here is what I want to perform:

    dir /b Z:\DLCS_core\R0230\analysis > C:\text\CoreAnalysisDir.txt

    Here is a code snippet
    FileStr = "Z:\\DLCS_core\R0230\analysis"; // mapped drive
    DirStr = "C:\\text\CoreAnalysisDir.txt";
    DOS_result = ExecProg( ‘dir /b’, FileStr, DirStr, ”, Flags );

    and then I end up with :"Z:\DLCS_core\R0230\analysis>"dir /X"

    Typing this out on the command line works as expected, only *.xml files appear in CoreAnalysisDir.txt

    Same when I create a batch file and run the batch file.

    Yet, when I attempt to call this batch file, No files appear in CoreAnalysisDir.txt.

    I searched using Ctrl-F1, and did not see anything on ExecProg.

    What do I need to do to get this to work?


    Clay Martin

    Did you try these flags ( _EP_Flags_ExeDos or _EP_FLAGS_COMSPEC) one at a time? The doc on this I found in Help-Cmac Users Guide(just do a search on execprog). It seems to indicate that for running a batch file you use _EP_FLAGS_COMSPEC. I think that would be the choice for a dos command, dir, (versus and actual .exe file)

    Have you tried examining the return code from the execprog call?
    Here are the error codes

    #define _execEC_ExecInUse -1
    #define _execEC_CmdTooLong -2

    Do you have the output file open in the editor when you are running the command?

    Is this ("Z:\DLCS_core\R0230\analysis>"dir /X") the total contents of the output file? Including the quotes? Any idea where the /X comes from since you don’t seem to be passing that in anywhere?

    Do you have this
    #include WinExec.sh
    in the file you are calling your cmac macro from?

    Do you see the command line window when you run the macro?




    The return code from ExecProg is 0

    The file is not open in the editor when I run this macro;

    The output of CoreAnalysisDir.txt is:

    Z:\DLCS_core\R0230\analysis>"dir /X"

    As mentioned before, the dir /X used to be in C:/bat/dir.bat, but no longer is. I am not sure where the dir /X is coming from; as I have
    searched for dir.bat via Windows search, and it did not turn up anything on the C: drive.

    #include WinExec.sh is in the file.

    I see a command line briefly when I run this macro(approximately 1 second, then disappears).

    The function that I use is this:
    void DirList() // Create a customized batch file for a directory listing
    str VersionStr = "R0230";
    int Flags, DOS_result;
    str OutputFile,WorkingDir,FileList;
    str CText = "C:\\text\\";
    str SlashStr = "\\";
    str ZStr = "Z:\\";
    str AD = "AnalysisDir.txt";
    str AStr = "analysis";

    str StrType = "Core";
    str DLCSStr = "DLCS_core";

    OutputFile = CText + StrType + AD;
    WorkingDir = ZStr + DLCSStr + SlashStr+VersionStr + SlashStr+AStr; // mapped drive
    // This is what I wish to use to generate the directory listing of the working directory
    FileList = ‘dir /b ‘+WorkingDir+’ > ‘+OutputFile;
    Here is the prototype for the call int ExecProg(str Prog, // = Parse_Str("/PROG=", Mparm_Str),// The command line
    str Working_Dir, // Parse_Str("/WD=",Mparm_Str),
    str StdOut_File, // = Parse_Str("/RED=", Mparm_Str), // The filename to output STDOUT to (DOS .EXE files only)
    str StdErr_File, // = Parse_Str("/REDERR=", Mparm_Str),// The filename to output STDERR to (DOS .EXE files only)
    int Flags // = Parse_Int("/FLAGS=", Mparm_Str ) // Flags; see #define _EP_FLAGS_xxxx above
    Flags = _EP_Flags_COMSPEC; // Run as a Dos program
    MsgDlg (FileList, "Status", "", 1);
    DOS_result = ExecProg( "dir /b", WorkingDir, OutputFile, ”, Flags );
    if(DOS_result != 0)
    MsgDlg ("DOS_result is " + str(DOS_result), "Error", "", 1);
    } // end if(DOS_result != 0)
    } // CreateDirList

    Clay Martin

    Did you try searching the Z drive for dir.bat? I noticed from your first posted macro, to the last output you reported the dir /X is constant. In your first macro you did not provide execprog with a working directory, so it used the Multi-Edit (ME) one thus:
    C:\Program Files\Multi-Edit 2008>"dir /X"
    in your last output, you had provided execprog with the directory on the Z drive as the working directory, thus:
    Z:\DLCS_core\R0230\analysis>"dir /X"

    So it seems that something else is being run other than a dos command dir. It is odd that the output contains the command prompt.

    I see you echo out your strings that contain the output file name and the directory you want the dir from. I will assume that you looked closely to see if there was any missing or extra \’s, thus no need to switch to using single ‘ instead of ".

    Have you tried having the macro execute a batch file with the full dir command (suggestion, name it something other than dir.bat) just to see the result. If that works you could have your macro write a batch file (with all the directory and output targets specified in the bat file) save it, run it, and delete it.



    Hi CLay,

    dir.bat does not exist on the Z drive.

    I have created a dirNew.bat file which consists of:

    dir /b Z:\DLCS_core\R0230\analysis > C:\text\CoreAnalysisDir.txt

    If I use the ExecProg with this functionality:

    [code:26d5o2g0]DOS_result = ExecProg("c:\\bat\\dirNew.bat", ”, ”, ”, Flags );[/code:26d5o2g0]

    the resultant file is:

    C:\Program Files\Multi-Edit 2008>"dir /X"

    Clay Martin

    And that text was located in the file:
    or some where else?


    located in C:\text\CoreAnalysisDir.txt

    Clay Martin

    So it seems that the batch file is being executed, otherwise the redirect to C:\text\CoreAnalysisDir.txt would not happen as that file is not mentioned in the execprog call. So this means that what is happening (strange output), is doing so outside of ME. The ME directory being mentioned in the output is consistent with not providing execprog a working directory so it uses the ME install directory as the working directory for executing the bat file.

    You indicated earlier that if you just execute the dos command dir from a command line prompt you get the expected results. Have you tried executing dirNew.bat from the command prompt? It would be especially critical to cd to the ME install directory (C:\Program Files\Multi-Edit 2008) before running the dirNew.bat file, and try running the bat file again from some other directory.



    Clay, I have included an attachment. The top window is cd’ing to C:\Program Files\Multi-Edit 2008, then the bottom dialog is showing dirNew.bat being run via a different directory.

    The expected output appears in c:/text/CoreAnalysisDir.txt

    I then ran dirNew.bat from the mew directory, and get the expected output in c:/text/CoreAnalysisDir.txt.

    If I run this
    [code:252o63ko]DOS_result = ExecProg("mem", ”, OutputFile, ”, Flags );[/code:252o63ko], for example, I end up with

    655360 bytes total conventional memory
    655360 bytes available to MS-DOS
    597952 largest executable program size

    1048576 bytes total contiguous extended memory
    0 bytes available contiguous extended memory
    941056 bytes available XMS memory
    MS-DOS resident in High Memory Area
    in c:/text/CoreAnalysisDir.txt.

    If I use this:
    [code:252o63ko]DOS_result = ExecProg("dir", ”, OutputFile, ”, Flags );[/code:252o63ko]
    I end up with this:

    C:\DXL>"dir /X"

    DXL is a valid directory, but is nowhere in ExecProg.
    OutputFile is defined as "C:\\text\\CoreAnalysisDir.txt";

    Performing this [code:252o63ko]DOS_result = ExecProg("dir /b", WorkingDir, OutputFile, ”, Flags );[/code:252o63ko]results in:
    Z:\DLCS_core\R0242\analysis>"dir /X" in c:/text/CoreAnalysisDir.txt.

    Using this [code:252o63ko]DOS_result = ExecProg( "c:\\test\\dirnew.bat", WorkingDir, OutputFile, ”, Flags );[/code:252o63ko] results in this:

    Z:\DLCS_core\R0242\analysis>dir /b Z:\DLCS_core\R0242\analysis 1>C:\text\CoreAnalysisDir.txt
    in c:/text/CoreAnalysisDir.txt.

    Clay Martin

    I did a search for dir /X in the ME source files, just in case, did not find it.

    Since running the batch file from the command prompt, results in the expected output, and from your last example (DOS_result = ExecProg( "c:\\test\\dirnew.bat", WorkingDir, OutputFile, ”, Flags );),
    you seem to get the contents of the bat file placed in the output file (not the result of executing the batch file), possibly you need to play with the flags (although your mem example seems to work as expected with the same flags as you are using for your dir /b and dirnew.bat) when running a bat file so that it gets executed, not echoed. Would be interesting if in this test (DOS_result = ExecProg( "c:\\test\\dirnew.bat", WorkingDir, OutputFile, ”, Flags );), we had some comments in the bat file to see if they show up in the output also. At least the dirnew.bat test did not yield dir /X.

    Could you try searching your system for a file called dir.exe? I just can’t figure where the dir /X is coming from.

    Might try running the execprog test where it runs dirnew.bat with just the flag _EP_Flags_ExeAuto. Might also try this flag too: _EP_Flags_SkipExec.

    Did you ever try running ExecProg("dir", ”, OutputFile, ”, Flags ); with just the _EP_Flags_ExeDos flag?

    I did notice that in the output of:
    Z:\DLCS_core\R0242\analysis>dir /b Z:\DLCS_core\R0242\analysis 1>C:\text\CoreAnalysisDir.txt
    The number 1, was that part of the bat file?

    Something else, when using long file names/paths you may want to process them this way:
    str filename = "file with long file name or path";
    str strFile = TranslateCmdLine(‘<LFN>’ + filename, ”);



    I changed the flag to _SkipExec, and ExecProg() now works as expected!

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.