![]() |
|
[Batch] Help w/ Wierd Spacing Issue - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Coding (https://sinister.ly/Forum-Coding--71) +--- Thread: [Batch] Help w/ Wierd Spacing Issue (/Thread-Batch-Help-w-Wierd-Spacing-Issue) Pages:
1
2
|
RE: [Batch] Help w/ Wierd Spacing Issue - 0xDEAD10CC - 03-23-2014 That sounds like a make belief story to me, no that's not it. Post your code in code tags please. Code: @echo off& setlocal enabledelayedexpansion
set outfile=Z:\batch.txt
:: save to file
set name=Bob
echo %name%> %outfile%
call :get_name
:: resave the name to file
echo %name%> %outfile%
call :get_name
:: dummy if statement (just for proof)
set name=Billy
if 1==1 echo %name%> %outfile%
call :get_name
goto :eof
:: grab name from file and show value
:get_name
set /p name=<%outfile%
echo Variable created from file: %name%
goto :eofNo spaces... Code: Variable created from file: Bob
Variable created from file: Bob
Variable created from file: BillyRE: [Batch] Help w/ Wierd Spacing Issue - DarkMuse - 03-23-2014 (03-23-2014, 01:45 AM)0xDEAD10CC Wrote: That sounds like a make belief story to me, no that's not it. Post your code in code tags please. So I fixed everything, so it seems. If you would like, give it another shot and see if you cant find any issues! Thank you so much for all your help! (I resubmitted the updated version and changed the version number to 2.0) RE: [Batch] Help w/ Wierd Spacing Issue - 0xDEAD10CC - 03-23-2014 Instead of setting root to %CD% you can also do this: Code: set root=%~dp0Which is equivalent to: Code: set root=%cd%\I'd suggest creating some functions though. RE: [Batch] Help w/ Wierd Spacing Issue - DarkMuse - 03-23-2014 (03-23-2014, 05:23 AM)0xDEAD10CC Wrote: I'd suggest creating some functions though. Like what? You got to remember I'm only a script kiddie with le Google for extra help. RE: [Batch] Help w/ Wierd Spacing Issue - 0xDEAD10CC - 03-23-2014 You could also have files... Code: @echo off&setlocal enabledelayedexpansion
call get_username.batIn get_username.bat, you could have everything that would grab the user input. Then you can use it later. Example: main.bat: Code: @echo off&setlocal enabledelayedexpansion
call functions1.bat
echo %user%functions1.bat: Code: set user=BobOutput: Code: BobFor a simple function: Code: @echo off&setlocal enabledelayedexpansion
call :get_username
echo %user%
pause&goto :eof
:get_username
set /p user=Enter a username:
goto :eofThe other way you could set it up is have a file that just holds related functions, and call functions from within the file externally. RE: [Batch] Help w/ Wierd Spacing Issue - DarkMuse - 03-23-2014 (03-23-2014, 05:32 AM)0xDEAD10CC Wrote: You could also have files...But why do all that extra work? What good would it do for the program specifically? RE: [Batch] Help w/ Wierd Spacing Issue - 0xDEAD10CC - 03-23-2014 (03-23-2014, 05:51 AM)DarkMuse Wrote: But why do all that extra work? What good would it do for the program specifically? Why do people use classes, structs, and other datatypes along with functions in other languages, and separate concerns within separate files in ANY program? Think... This is a lot easier to manage: Code: @echo off&setlocal enabledelayedexpansion
call functions1.bat :func1 arg1 arg2Code: call %*&goto :eof
:func1
echo Hi you called func1 with args: %1 %2
goto :eof
:func2
echo Hi you called func2 with args: %1 %2
goto :eof
:func3
echo Hi you called func3 with args: %1 %2
goto :eofLook at a case where this may be useful: main.bat Code: @echo off&setlocal enabledelayedexpansion
call functions1.bat :func1 arg1 arg2
echo.&echo.Testing with DEBUG mode on...&echo.
set DEBUG=1
call myfunctions.bat :func1 arg1 arg2myfunctions.bat Code: setlocal enabledelayedexpansion
if defined DEBUG (
set args=%*&if defined args set "args=!args:%1 =!"
echo.CALL ^> %1
echo.ARGS ^> !args!
echo.
)
call %*&goto :eof
::-------------------------------
:: FUNCTIONS
::-------------------------------
:func1
echo Hi you called func1 with args: %1 %2
goto :eof
:func2
echo Hi you called func2 with args: %1 %2
goto :eof
:func3
echo Hi you called func3 with args: %1 %2
goto :eofOUTPUT: Code: Hi you called func1 with args: arg1 arg2
Testing with DEBUG mode on...
CALL > :func1
ARGS > arg1 arg2
Hi you called func1 with args: arg1 arg2You don't see anything useful with this?.. RE: [Batch] Help w/ Wierd Spacing Issue - DarkMuse - 03-23-2014 (03-23-2014, 06:08 AM)0xDEAD10CC Wrote: Why do people use classes, structs, and other datatypes along with functions in other languages, and separate concerns within separate files in ANY program? Think...Mainly it's because a lot of this stuff is over my head right now. I have very, very basic knowledge and unless you would like to teach me more advanced terms I don't think it would be very beneficial for me to rip the working program apart to recode it at this point. Although I do hope to do so in the future as it will make things easier. |