News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Bat files Grrrrrrrrrr!

Started by Rainstorm, March 24, 2009, 12:57:01 PM

Previous topic - Next topic

Rainstorm

Hi.
just having a prob with this, don't know much about bat files.
when there is no %1 the if doesn't seem to trigger, when it should.

I've just dloaded windows power shell for Xp.- gonna give it a look.. & maybe just dump this & use that.

thanks!

@echo off

set lpath=%~dp0
echo path = %lpath%
pause

if "%1" == "" (
echo if triggered
set lpath=%~n0
echo lpath - %lpath%
) else (
echo else triggered
pause
)


EDITED : changed the curly braces to parentheses

ToutEnMasm

OH,
If i am a batch file , i used %1 %2 ...%N to design the arguments in the command line.
The %1 is the first word in the command line ,the %2 the second word....
What is %~dp0 in this enumeration ?,I don't know.

The { seems to be only used in c++

Seems you need some samples and a help file before writing a batch
http://www.computerhope.com/batch.htm

Jimg

Wow have things changed since the last time I used batch files.


I changed the curly braces to parens and it worked as expected.

Rainstorm

ToutenAsm >>
QuoteWhat is %~dp0 in this enumeration ?,I don't know.
The { seems to be only used in c++
The '}' was an error I corrected it , I know nothing of C++ anyhow - the problem is still the same though.

%~dp0 means,  return just the drive & path of the batchfile.
%~n0 would return just the name
%~n1 would return only the name in the 1st argument (assuming it was a filepath)
etc. . . .

Rainstorm

still doesn't work here.. when i double click the file.
%1 is nothing.. so am expecting it to trigger the if statement & the echo in the if statement should display.(I've echoed %1 to be sure)
-- using Winxp pro -SP2

[edit] Jimq ; which version of windows are you running ?

Jimg

double click the file???????

Drop to a command prompt and run it!

Im using XP SP2 also pro.


Okay, I added an extra pause at the very end and double clicked on the batch file, and it seems to work.

You know lpath only holds for that one run, right?

Rainstorm

 no way i can get it to work the same way.. by double clicking ?
If i run it from a command prompt it works as expected

edit::  guess i cross posted ; )
just read yuor reply.., dunnow hy the pause helped but double clicking works here too now

thanks!!

Jimg

What are you trying to accomplish?  I assumed this was just a test for something bigger.  Are you trying to permanently set an environment variable?

Rainstorm

I was just writing some bat files to handle some of teh basic assembly commandline stuff in convenient ways.. this was a section of that code i was working on that..was giving a problem.
not setting an environment variable.

edit: as to why the pause helped, just realised there wasn't a 'pause' after the echo in the if ; )

t  y

Jimg

The environment variable you set should be good throughout the command session you initiate by double-clicking the bat file.

It should work for what you are doing.  There must be a different problem.

Rainstorm

it works now.. so far in what i tried  :thumbu

jj2007

A variant.

@echo off
echo.
echo.
echo.

if 0%1==0 (
echo arg1 is empty
set lpath=%~n0
echo lpath - %lpath%
) else (
echo This is arg1: %1
)

Rainstorm

#12
jj nice one  :thumbu, i'll remember that.. : )

t y

askm

REM Some example lines in a *.bat of mine...

If {%1}=={} @echo No parameter specified.&goto :EOF

If exist "%1.obj" del "%1.obj"
If exist "%1.exe" del "%1.exe"
If exist "%~dpn1.obj" del "%~dpn1.obj"
If exist "%~dpn1.exe" del "%~dpn1.exe"

REM pause

If exist "%1.cpp" goto cpp
If {"%~x1"}=={".cpp"} goto cpp

If exist "%1.cc" goto cc
If {"%~x1"}=={".cc"} goto cc

If {"%~x1"}=={".c"} goto noaddc

If not {%2} == {} echo %2
If not {%3} == {} echo %3
If not {%4} == {} echo %4
If not {%5} == {} echo %5

:cpp

:cc

:noaddc

pause