writing "\" in a batch file
J-E Petit
the following function writes lines for a batch file. The associated .exe is called by writing "\hysplit\exec\hyts_std", but it comes out as "\\hysplit\\exec\\hyts_std", and thus the program does not execute. How should it be written in the beginning to be saved in the proper way?
Thanks!
J-E
Function BatchFile(dt)
variable dt
String shortDateStr = Secs2Date(dt, -1)
variable day, month, year, dayOfWeek
sscanf shortDateStr, "%d/%d/%d (%d)", day, month, year, dayOfWeek
Variable time = mod(dt, 24*60*60)
variable hour=trunc(time/(60*60))
string year_str=num2str(year)[2,3]
string month_str=num2str(month)
if (strlen(month_str)==1)
month_str="0"+month_str
endif
string day_str=num2str(day)
if (strlen(day_str)==1)
day_str="0"+day_str
endif
string hour_str=num2str(hour)
if (strlen(hour_str)==1)
hour_str="0"+hour_str
endif
NVAR/Z trajduration=root:trajduration
SVAR/Z PathToMetzFile=root:PathToMetFile
SVAR/Z Trajprefix=trajprefix
SVAR/Z Pathtotrajfolder=root:pathtotrajfolder
string Batch_str
Batch_str="echo "+year_str+" "+month_str+" "+day_str+" "+hour_str+" >CONTROL;"
Batch_str+="echo 1 >>CONTROL;"
Batch_str+="echo 49.11 6.23 50 >>CONTROL;"
Batch_str+="echo "+num2str(trajduration)+" >>CONTROL;"
Batch_str+="echo 0 >>CONTROL;"
Batch_str+="echo 10000 >>CONTROL;"
string gdasfile_list=OtherGDASFile(dt,trajduration)
variable NbMetFile=itemsinlist(gdasfile_list)
Batch_str+="echo "+num2str(NbMetFile)+" >>CONTROL;"
variable i
for (i=0;i<NbMetFile;i+=1)
Batch_str+="echo "+PathToMetzFile+" >>CONTROL;"
Batch_str+="echo "+stringfromlist(i,gdasfile_list)+" >>CONTROL;"
endfor
Batch_str+="echo "+pathtotrajfolder+" >>CONTROL;"
Batch_str+="echo "+trajprefix+year_str+month_str+day_str+hour_str+ " >>CONTROL;"
Batch_str+=";"
Batch_str+="\hysplit4\exec\hyts_std;"
print Batch_str
Make/T/O/N=(ItemsInList(batch_str, ";")) batch_txt
batch_txt = StringFromList(p, batch_str, ";")
Newpath/O BatchPath, "C:hysplit4:working:"
Save/T/G/O/M="\r\n"/P=BatchPath Batch_txt as "batch_run.bat"
End Function
variable dt
String shortDateStr = Secs2Date(dt, -1)
variable day, month, year, dayOfWeek
sscanf shortDateStr, "%d/%d/%d (%d)", day, month, year, dayOfWeek
Variable time = mod(dt, 24*60*60)
variable hour=trunc(time/(60*60))
string year_str=num2str(year)[2,3]
string month_str=num2str(month)
if (strlen(month_str)==1)
month_str="0"+month_str
endif
string day_str=num2str(day)
if (strlen(day_str)==1)
day_str="0"+day_str
endif
string hour_str=num2str(hour)
if (strlen(hour_str)==1)
hour_str="0"+hour_str
endif
NVAR/Z trajduration=root:trajduration
SVAR/Z PathToMetzFile=root:PathToMetFile
SVAR/Z Trajprefix=trajprefix
SVAR/Z Pathtotrajfolder=root:pathtotrajfolder
string Batch_str
Batch_str="echo "+year_str+" "+month_str+" "+day_str+" "+hour_str+" >CONTROL;"
Batch_str+="echo 1 >>CONTROL;"
Batch_str+="echo 49.11 6.23 50 >>CONTROL;"
Batch_str+="echo "+num2str(trajduration)+" >>CONTROL;"
Batch_str+="echo 0 >>CONTROL;"
Batch_str+="echo 10000 >>CONTROL;"
string gdasfile_list=OtherGDASFile(dt,trajduration)
variable NbMetFile=itemsinlist(gdasfile_list)
Batch_str+="echo "+num2str(NbMetFile)+" >>CONTROL;"
variable i
for (i=0;i<NbMetFile;i+=1)
Batch_str+="echo "+PathToMetzFile+" >>CONTROL;"
Batch_str+="echo "+stringfromlist(i,gdasfile_list)+" >>CONTROL;"
endfor
Batch_str+="echo "+pathtotrajfolder+" >>CONTROL;"
Batch_str+="echo "+trajprefix+year_str+month_str+day_str+hour_str+ " >>CONTROL;"
Batch_str+=";"
Batch_str+="\hysplit4\exec\hyts_std;"
print Batch_str
Make/T/O/N=(ItemsInList(batch_str, ";")) batch_txt
batch_txt = StringFromList(p, batch_str, ";")
Newpath/O BatchPath, "C:hysplit4:working:"
Save/T/G/O/M="\r\n"/P=BatchPath Batch_txt as "batch_run.bat"
End Function
I'm not sure where you are seeing double-backslashes. Possibly you are seeing it in a literal string in the Igor debugger. In that case, a double-backslash means that there is one backslash character in the string. The debugger is simply displaying it as you would need to enter it in a command.
April 15, 2016 at 07:08 am - Permalink
"\\hysplit4\\exec\\hyts_std;"
, then in the batch it is written "\\hysplit4\\exec\\hyts_std".Anyway, strangely, using "/hysplit4/exec/hyts_std" works.... so I'll go for that
the other problem that I'm facing is to execute the batch file:
while executing
executeScriptText/B/Z "C:hysplit4:working:batch_run.bat"
doesn't do anything,executeScriptText/B/Z "C:\hysplit4\working\batch_run.bat"
launches the batch file, but leads to incomplete calculation. (just to mention that double clicking on the batch file works properly :) )April 15, 2016 at 07:20 am - Permalink