A (hopefully) simple question

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
LemuresExMachina
Posts: 2
Joined: 11 Feb 2008 09:12

A (hopefully) simple question

#1 Post by LemuresExMachina » 11 Feb 2008 09:26

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

LemuresExMachina
Posts: 2
Joined: 11 Feb 2008 09:12

#2 Post by LemuresExMachina » 11 Feb 2008 10:15

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;
}

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#3 Post by DosItHelp » 11 Feb 2008 21:09

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:

Post Reply