Thread: open several files and execute?

  1. #16
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Did you try putting 'echo' before normfet.exe in the batch file? Cos it says 'prefix' and I'm wondering whether the ouput file is correctly named.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  2. #17
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    This is probably slightly clearer:
    Code:
    #include <stdio.h> 
    #include <string.h> 
    
    int main(int argc, char *argv[])
    {
      char command_string[BUFSIZ] = {0};
      snprintf (command_string, "normfet.exe %s %snm -nml -ftr", argv[1], argv[1]);
      
      printf ("Executing %s\n", command_string);
      system (command_string);
      
      return 0;
    }
    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  3. #18
    Registered User
    Join Date
    Aug 2007
    Posts
    28
    Quote Originally Posted by QuantumPete View Post
    This is probably slightly clearer

    QuantumPete
    Tried out your solution, it just opens the files (xyz) in notepad
    I tried my last solution again, it does not error out: the output of the program is normal and the prefix of the input file is there and it ends it the nm (output file name). But again, nothing is written.

    But no error happens now

  4. #19
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by autopilot View Post
    Tried out your solution, it just opens the files (xyz) in notepad
    I tried my last solution again, it does not error out: the output of the program is normal and the prefix of the input file is there and it ends it the nm (output file name). But again, nothing is written.

    But no error happens now
    Wierd. But it works if you don't use the for loop, but run the normfet.exe for each file individually?

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  5. #20
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    When batch lets you down, use C

    Code:
    #include <windows.h>
    #include <stdio.h>
    
    int main(void)
    {
        WIN32_FIND_DATA FindFileData;
        HANDLE hFind;
        char cmd[256];
    
        if((hFind = FindFirstFile(".\\*.xyz", &FindFileData)) == INVALID_HANDLE_VALUE)
        {
            puts("ABANDON SHIP, Y'ARRH");
            return 1;
        }
    
        do {
            if(strcmp(FindFileData.cFileName, ".") == 0 || strcmp(FindFileData.cFileName, "..") == 0)
                continue;
    
            sprintf(cmd, "normfet.exe &#37;s %snm -nml -ftr", FindFileData.cFileName, FindFileData.cFileName);
            if(CreateProcess(NULL, cmd, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, NULL) != 0)
                printf("Run on %s...", FindFileData.cFileName);
    
        } while (FindNextFile(hFind, &FindFileData) != 0);
    
        FindClose(hFind);
        return 0;
    }
    Untested, Fix at will.
    Last edited by zacs7; 09-11-2007 at 05:12 AM.

  6. #21
    Registered User
    Join Date
    Aug 2007
    Posts
    28
    Quote Originally Posted by zacs7 View Post
    When batch lets you down, use C
    Untested, Fix at will.
    21 C:\3d\teste.c too few arguments to function `CreateProcessA'

  7. #22
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Stick a zero in front of NORMAL_PRIORITY_CLASS, I think.

    I think Salem meant that "It's up to you to fix it".

    --
    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.

  8. #23
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Salem said what?

    If you confused me with Salem, Either I'm getting pretty skilled, or you need glasses

  9. #24
    Registered User
    Join Date
    Aug 2007
    Posts
    28
    Again, if i run my program like this "tnormfet.exe 5.xyz" it calls norfet.exe and it works great and outputs the file(5.xyznw)
    How would i change it to scan the files on a dir and automatically loop the program for all of them?

    Code:
    #include <stdio.h> 
    #include <string.h> 
    
    int main(int argc, char *argv[])
    {
      char child1[] = "normfet.exe";
      char child2[BUFSIZ];
      char child3[BUFSIZ];
      
      // nome saida
      strcpy (child3, argv[1]);
      strcat (child3, "nw");
    
      strcpy (child2, child1);
      strcat (child2, " ");
      strcat (child2, argv[1]);
      strcat (child2, " ");
      strcat (child2, child3);
      strcat (child2, " -nml -ftr");
      
      printf ("Executing %s\n", child2);
      system (child2);
      
      return 0;
    }

  10. #25
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by zacs7 View Post
    Salem said what?

    If you confused me with Salem, Either I'm getting pretty skilled, or you need glasses
    Ah, sorry, yes I got confused, and as I only tested my eyes for these glasses about 3 months ago, I think they are OK still (actually, only 2 weeks or so ago, they checked my eyesight for a medical test too, and that was OK too). Probably more bitrot in the RAM.

    --
    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.

  11. #26
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    That's pretty much what mine does, just replace CreateProcess with system(), a little bit of speed shouldn't matter.

  12. #27
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote Originally Posted by autopilot View Post
    Again, if i run my program like this "tnormfet.exe 5.xyz" it calls norfet.exe and it works great and outputs the file(5.xyznw)
    How would i change it to scan the files on a dir and automatically loop the program for all of them?
    By reading the FAQ perhaps?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2 files 1 project
    By mat13mat in forum C++ Programming
    Replies: 3
    Last Post: 04-26-2008, 08:14 AM
  2. Ressources files
    By mikahell in forum Windows Programming
    Replies: 4
    Last Post: 06-19-2006, 06:50 AM
  3. Files not updating in folder
    By BobS0327 in forum Tech Board
    Replies: 4
    Last Post: 06-06-2005, 05:55 PM
  4. execute files from dir
    By xxxrugby in forum C Programming
    Replies: 2
    Last Post: 04-08-2005, 01:33 PM
  5. how to execute more than one files??
    By myer_784 in forum C Programming
    Replies: 8
    Last Post: 03-15-2005, 11:52 PM