Thread: C system call and msdos batch files.

  1. #1
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794

    C system call and msdos batch files.

    I had a batch file which had the folowing line in, which ran fine, basically it produced a list of .log files.
    Code:
    dir c:\"Program Files"\"William Hill Poker"\log\XP02202685\2009011318505875\*.log /b /s >>dirs.doc

    However when I tried to run it from a C program using the system command eg:
    Code:
    system("mycreatelogfilelist.bat");
    It does not work, it comes back with, I think "Too many parameters".
    I think this is due to MSDOS really more than a 'C' thing but does anyone know
    how I could have got it to work? It is I think something to do with the way it parses
    the line being different when it is called from C but I don't know how to get around it.
    Last edited by esbo; 01-15-2009 at 12:28 AM.

  2. #2
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    404
    That is a valid call to system AFAIK. Show some more code. Are you sure the error you are receiving is from that line?

    Also, try maybe putting quotes around the whole path, not just a part of it:
    "c:\Program Files\William Hill Poker\log\XP02202685\2009011318505875\*.log"

  3. #3
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    That gives parameter format not correct.
    I have shortened the test
    Code:
    
    dir  c:\djgpp = works
    dir "c:\djgpp"   = parameter format not correct.
    dir  c:\"djgpp" = too many parameters
    
    As I said I don't think sysem uses the same thing (shell?)to process the line or something like that.
    I got around it by calling the batch file from another batchfile, but I can't get it to work from
    a c program, it does not like space or quotes.
    Last edited by esbo; 01-15-2009 at 03:06 AM.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    What about one of the spawn functions?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  5. #5
    Registered User ch4's Avatar
    Join Date
    Jan 2007
    Posts
    154
    Are .bat and .exe located in the same directory ?

  6. #6
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Do you need to escape the double quotes? What about no quotes at all?
    Mainframe assembler programmer by trade. C coder when I can.

  7. #7
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Or, maybe bat files don't support the long names, so you have to use the PROGRA~1 flavor syntax?
    Mainframe assembler programmer by trade. C coder when I can.

  8. #8
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by cpjust View Post
    What about one of the spawn functions?
    No that seems to give the same sort of errors as system() unfortunately.
    I had to guess oneof the values to pass as 0, which it seemed to accept.
    Last edited by esbo; 01-15-2009 at 09:55 AM.

  9. #9
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by ch4 View Post
    Are .bat and .exe located in the same directory ?
    Yes but I specify ".bat" to avoid confusion.

  10. #10
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Dino View Post
    Do you need to escape the double quotes? What about no quotes at all?

    Tried both - no joy.

  11. #11
    Registered User
    Join Date
    Apr 2006
    Posts
    58
    You may also need to escape the backslashes.

    Code:
    dir "c:\\Program Files\\William Hill Poker\\log\\XP02202685\\2009011318505875\\*.log" /b /s >>dirs.doc
    Try that and see if that works.

  12. #12
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by samf View Post
    You may also need to escape the backslashes.

    Code:
    dir "c:\\Program Files\\William Hill Poker\\log\\XP02202685\\2009011318505875\\*.log" /b /s >>dirs.doc
    Try that and see if that works.
    Unfortunately not - looked promising though!!

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Are you by any chance using Turbo C or some other DOS compiler? If so, long filenames will not be supported, even for "system()"

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by matsp View Post
    Are you by any chance using Turbo C or some other DOS compiler? If so, long filenames will not be supported, even for "system()"

    --
    Mats
    djgpp of gcc or whatever it is called.
    It seems that's the case.

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by esbo View Post
    djgpp of gcc or whatever it is called.
    It seems that's the case.
    Yes, djgpp is a DOS compiler, so it applies DOS rules - including "filenames must be 8.3 format". Why not use gcc-mingw or some such? You obviously DO have Windows on your machine, so I don't see any harm in using Windows system functionality.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed