Go Back   SitePoint Forums > Forum Index > Program Your Site > Perl, Python and Other Languages
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Oct 29, 2009, 16:23   #1
Tigers!
SitePoint Zealot
 
Join Date: Jun 2006
Location: Australia
Posts: 153
Calling DOS batch file from C on Vista

Gudday all
Need to call a DOS batch file from C on my Vista or XP machine (but the code will eventually go on a Win2003/2007 machine).
Searching through the forums found a few previous threads which had some information but not quite.
I want to call a batch file from the C programme and pass one parameter from C to the batch.
The system call is
Code:
system("testing_parse_lines_DOS-2.bat oldrptname");
with the parameter being oldrptname. Note that oldrptname is a variable and contains data which will be different every time the C programme is run.
The batch file is
Code:
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2,3,4* delims=\" %%a in (moveTIFF.dat) do (
 set full_line=\%%a\%%b\%%c\%%d
 set file_name=%%d
 echo Full line: !full_line!
 echo File name: !file_name!
 echo.
 copy /b !file_name! !full_line! 
 )
 del RPT.dat
 del moveTiff.dat
 rename error.dat %1
and the parameter passed is %1.
The problem is that the renaming works up to a point. It changes the file name 'error.dat' to 'oldrptname' rather than the contents of the variable oldrptname. The data in oldrptname will always have the form "xxxxxxxx.RPT".
The batch file and the exe are in the same directory.
I tried the combination of
Code:
system("testing_parse_lines_DOS-2.bat" oldrptname);
but that throws up a compiler error.
Looking through other threads mention has been made of setting paths etc: but I am unsure whether that applies to the C or batch or both.
I am hoping that the error is a simple syntax error. Perhaps the way I pass the variable from C to the batch or the way I express it in the batch?
Tigers! is offline   Reply With Quote
Old Oct 29, 2009, 17:54   #2
Dan Grossman
Follow Me On Twitter: @djg
SitePoint Award Recipient
 
Dan Grossman's Avatar
 
Join Date: Aug 2000
Location: Philadephia, PA
Posts: 18,684
You need to construct the command for system(), you can't just put the variable name in a literal string.

http://irc.essex.ac.uk/www.iota-six....at_strncat.asp
Dan Grossman is online now   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 02:05.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved