The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => The Orphanage => Topic started by: Rainstorm on March 24, 2009, 12:57:01 PM

Title: Bat files Grrrrrrrrrr!
Post by: Rainstorm on March 24, 2009, 12:57:01 PM
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
Title: Re: Bat files Grrrrrrrrrr!
Post by: ToutEnMasm on March 24, 2009, 01:31:32 PM
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
Title: Re: Bat files Grrrrrrrrrr!
Post by: Jimg on March 24, 2009, 01:34:10 PM
Wow have things changed since the last time I used batch files.


I changed the curly braces to parens and it worked as expected.
Title: Re: Bat files Grrrrrrrrrr!
Post by: Rainstorm on March 24, 2009, 01:42:10 PM
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. . . .
Title: Re: Bat files Grrrrrrrrrr!
Post by: Rainstorm on March 24, 2009, 01:48:53 PM
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 ?
Title: Re: Bat files Grrrrrrrrrr!
Post by: Jimg on March 24, 2009, 01:57:15 PM
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?
Title: Re: Bat files Grrrrrrrrrr!
Post by: Rainstorm on March 24, 2009, 02:02:08 PM
 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!!
Title: Re: Bat files Grrrrrrrrrr!
Post by: Jimg on March 24, 2009, 02:05:41 PM
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?
Title: Re: Bat files Grrrrrrrrrr!
Post by: Rainstorm on March 24, 2009, 02:09:29 PM
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
Title: Re: Bat files Grrrrrrrrrr!
Post by: Jimg on March 24, 2009, 02:13:50 PM
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.
Title: Re: Bat files Grrrrrrrrrr!
Post by: Rainstorm on March 24, 2009, 02:17:43 PM
it works now.. so far in what i tried  :thumbu
Title: Re: Bat files Grrrrrrrrrr!
Post by: jj2007 on March 24, 2009, 02:23:59 PM
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
)
Title: Re: Bat files Grrrrrrrrrr!
Post by: Rainstorm on March 24, 2009, 02:28:19 PM
jj nice one  :thumbu, i'll remember that.. : )

t y
Title: Re: Bat files Grrrrrrrrrr!
Post by: askm on March 24, 2009, 02:57:04 PM
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