Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to compile a .bat file? or write a simple .exe to call it?  (Read 4140 times)

0 Members and 1 Guest are viewing this topic.

banjo67xxx

    Topic Starter


    Beginner

    Thanked: 4
    • Certifications: List
    • Computer: Specs
    • Experience: Guru
    • OS: Linux variant
    How to compile a .bat file? or write a simple .exe to call it?
    « on: November 28, 2009, 01:02:43 PM »
    Hi,

    I'm trying to intercept calls to a .exe to trace them (legit as my company wrote the .exe) as part of debugging, and I've suceeded in writing a short .bat file which does what I want after renaming the original command with -ORIG.

    the-command.bat
    Code: [Select]
    @echo off
    echo .|time >> logfile.txt
    echo %0 %* >> logfile.txt
    the-command-ORIG.exe %*

    The problem is that the customer's program is expecting to call the-command.exe not the-command.bat.

    I tried renaming the .bat file, but then it won't execute.
    I tried creating a shortcut with .exe extension to the .bat but that didn't work either.

    Is there a compiler I could use to convert it from .bat to .exe?
    or do I need to write a one-line program to call the .bat and compile it?
    or would it be a whole lot easier to write a C program to do the tracing instead?

    banjo67xxx

      Topic Starter


      Beginner

      Thanked: 4
      • Certifications: List
      • Computer: Specs
      • Experience: Guru
      • OS: Linux variant
      Re: How to compile a .bat file? or write a simple .exe to call it?
      « Reply #1 on: November 28, 2009, 08:34:03 PM »
      I've nearly solved it with MinGW and the following code

      Code: [Select]
      #include <unistd.h>
      #include <stdio.h>

      main(int argc, char *argv[])

      {
        argv[0] = "C:\\path\\etc\\the-command.bat";
        execv("C:\\path\\etc\\the-command.bat", argv);
        return 0;
      }

      I'll follow up on the final problems in the programming forum.