Page 1 of 1

A (hopefully) simple question

Posted: 11 Feb 2008 09:26
by LemuresExMachina
I've recently had to write a few batch files at work, and have been having some trouble with them. After a lot of attempts at doing everything I needed in the batch files themselfs I decided it would be better for me to stick to what I know, which is C. The trouble that I am haveing now is the following function/command line call:
C:\Sandbox\test\sigtest !count! result.md5 !checksum!
The sigtest is a command line application that takes the following three values, in this order:
A line offset into a file
File to parse
a return value to fill with the result (This is my problem)

After looking around on the web, the general work around seems to be to create and then delete a temp file, however do to memory constraints on the system I am working on this is not a possibility, can anybody offer any advice or assistance on my issue? He is the full code for the batch file.

Code: Select all

@ECHO OFF 
SETLOCAL ENABLEDELAYEDEXPANSION
set /a count=0
set checksum=0


FOR %%x in (C:\Sandbox\test\bin\*.*) Do (
C:\Sandbox\test\sigtest !count! result.md5 !checksum!
echo %%x
echo !checksum!
C:\Sandbox\test\md5 -c%%i %%x
IF ERRORLEVEL == 1 GOTO BAD
IF ERRORLEVEL == 2 GOTO NOFL
)

ECHO all good

PAUSE
CLS
EXIT 

:BAD
ECHO the parameters do not match
PAUSE
CLS
EXIT

:NOFL
ECHO file not found
PAUSE
CLS
EXIT

Posted: 11 Feb 2008 10:15
by LemuresExMachina
If it heps here is the C++ code that comprizes sigtest:

Code: Select all

#include <fstream>
#include <Windows.h>
using namespace std;

int main( int argc, char *argv[])
{
    fstream f;
    char buffer[512];
    char retbuffer[33];

    f.open(argv[2],ios_base::in);

    if(!f.is_open())
    {
    }
    for(int i = 0;i < atoi(argv[1]);i++)
    {
        f.getline(buffer,512,'\n');
    }

        f.getline(retbuffer,33,' ');
        //strcpy(argv[3],retbuffer);
        SetEnvironmentVariable(argv[3],retbuffer);
    f.close();
    return 0;
}

Posted: 11 Feb 2008 21:09
by DosItHelp
LemuresExMachina,

The term !checksum! resolves the checksum variable and passes 0 into the sigtest program. First thing to try is to remove the exclamation characters and just pass checksum like this:

C:\Sandbox\test\sigtest !count! result.md5 checksum

If it works fine now then great.
If not then probably because of the fact that the environment variables are being restored automatically when sigtest finishes. Here another approach:

In the C program print the result to the console, i.e.

Code: Select all

fprintf(stdout,retbuffer);


In the batch file use for /f ... to capture the output of sigtest:

Code: Select all

for /f %%A in ('C:\Sandbox\test\sigtest !count! result.md5') do set "checksum=%%A"


DOS IT HELP? :wink: