|
Answer» Has anyone any familiarity with CALLING batch files from C? I want to call a batch file from a C programme and pass one parameter from the C to the batch. The system call in the C programme is Code: [Select]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: [Select]@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". I am hoping that the error is a simple syntax error.I don't KNOW C, but I do know that oldrptname in system("testing_parse_lines_DOS-2.bat oldrptname"); is being run as a switch to the batch file as itself, no variable. Perhaps if you show me how to call a variable in C I can HELP you more. Scrap any further comments in this post. I solved it. I will now go and salsh my wrists for stupidity!
I have done a little further work. Currently I am calling the batch file with the new filename present to see how it behaves. Code: [Select]testing_parse_lines_DOS-2.bat 20090220-TESTMOVE.RPT I wrote a little batch file for testing Code: [Select]@echo off echo %1 echo finished moving of files rename error.dat %1 This batch file will echo the parameter (20090220-TESTMOVE.RPT) send to it and then attempt to change the file name of error.dat to the parameter (20090220-TESTMOVE.RPT). Unfortunately it gives an error message. See attachment I am wondering if the error message is related to my use of %1 in the 'rename error.dat %1'? Is the syntax, grammar ETC: correct? Or is it something else?
[Saving space, attachment deleted by admin]place the %1 in quotes, as in, "%1". Code: [Select]@echo off echo %1 echo finished moving of files rename error.dat %1
There is nothing wrong with your code. Works fine. You cannot have duplicate file names in the same directory.File cannot be found could mean the file does not exist (error.dat) or there is a spelling error.
Code: [Select]C:\Temp>dir Volume in drive C is xpSystem Volume Serial Number is 60D0-12D6
Directory of C:\Temp
11/04/2009 09:22 AM <DIR> . 11/04/2009 09:22 AM <DIR> .. 11/04/2009 09:16 AM 2 error.dat 11/04/2009 09:16 AM 73 Test.bat 2 File(s) 75 bytes 2 Dir(s) 1,739,354,112 bytes free
C:\Temp>test 20090220-TESTMOVE.RPT 20090220-TESTMOVE.RPT finished moving of files
C:\Temp>dir Volume in drive C is xpSystem Volume Serial Number is 60D0-12D6
Directory of C:\Temp
11/04/2009 09:22 AM <DIR> . 11/04/2009 09:22 AM <DIR> .. 11/04/2009 09:16 AM 2 20090220-TESTMOVE.RPT 11/04/2009 09:16 AM 73 Test.bat 2 File(s) 75 bytes 2 Dir(s) 1,739,354,112 bytes free
C:\Temp>
Quote place the %1 in quotes, as in, "%1".
Quotes are only required if a file name has embedded spaces or special characters that would mess up the interpreter. That does not appear to be the case here.
I was thinking more along hte LINES of the hyphen, but I checked, hyphen is acceptable either way.
|