omussmann
Goto Top

Wert aus einem TEXT-File in eine Batchdatei als Variable übernehmen

Hallo liebe Administratorengemeinde,

mich plagt folgendes Problem:

Ich muss regelmäßig Werte aus einer SQL Datenbank löschen. Die Werte stehen in verschiedenen Tabellen. Dafür habe ich mir folgende Script geschrieben:

@echo off
cls
color 70

set bu=15

echo.
echo Buchung wird gelöscht ...
echo Bitte warten ...
echo.

osql.exe -E -Q "delete from projekt.projektuser.re where konto=%bu%"
osql.exe -E -Q "delete from projekt.projektuser.pe where konto=%bu%"
osql.exe -E -Q "delete from projekt.projektuser.te where konto=%bu%"
osql.exe -E -Q "delete from projekt.projektuser.ke where konto=%bu%"
osql.exe -E -Q "delete from projekt.projektuser.ee where konto=%bu%"

goto :EOF

Das Script funktioniert, nur muss ich jedesmal das Script öffnen und die Variable 'bu' ändern, um den nächsten Wert zu löschen

Ideal wäre es, wenn ich in einer Textdatei den Wert eingebe und den Wert der Variable 'bu' und über das Script auslese. Habt Ihr eine Idee, wie das am sinnvollsten gehen würde? Vielen Dank für Euren Support.

LG

Content-Key: 137210

Url: https://administrator.de/contentid/137210

Printed on: April 19, 2024 at 14:04 o'clock

Member: Snowman25
Snowman25 Mar 02, 2010 at 13:29:12 (UTC)
Goto Top
die batch:
@Echo off
color 70
cls
for /F %%i in (bu.values) do (
	osql.exe -E -Q "delete from projekt.projektuser.re where konto=%%i"  
	osql.exe -E -Q "delete from projekt.projektuser.pe where konto=%%i"  
	osql.exe -E -Q "delete from projekt.projektuser.te where konto=%%i"  
	osql.exe -E -Q "delete from projekt.projektuser.ke where konto=%%i"  
	osql.exe -E -Q "delete from projekt.projektuser.ee where konto=%%i"  
)

in die Datei bu.value kommen dann eben deinen werte
Member: OMussmann
OMussmann Mar 02, 2010 at 13:42:09 (UTC)
Goto Top
Okay, funktionier. Super und danke.

Fragen noch, weil ich es einfach verstehen will:

- Wofür steht /F?
- Warum zweimal %%?
- i kann eine belibiege Variable sein, also auch bu?


Danke

LG
Oliver
Member: Snowman25
Snowman25 Mar 02, 2010 at 13:50:48 (UTC)
Goto Top
Zitat von @OMussmann:
- Wofür steht /F?
Gute Frage. Höchstwahrscheinlich für File. Lies dir dazu mal die Hilfe von for durch. Hier ein kleiner Auszug:
Iterating and file parsing
Use file parsing to process command output, strings and file content. Use iterative variables to define the content or strings you want to examine and use the various ParsingKeywords options to further modify the parsing. Use the ParsingKeywords token option to specify which tokens should be passed as iterative variables. Note that when used without the token option, /F will only examine the first token.


File parsing consists of reading the output, string or file content, breaking it up into individual lines of text and then parsing each line into zero or more tokens. The for loop is then called with the iterative variable value set to the token. By default, /F passes the first blank separated token from each line of each file. Blank lines are skipped.

- Warum zweimal %%?
Damit die werte in der For-Schleife in einem batchfile richtig geparst werden. Wenn du den Befehl direkt am prompt eingibst, dann nur ein %

- i kann eine belibiege Variable sein, also auch bu?
Jein! Du darfst zwar einen beliebigen Namen wählen, allerdings darf dieser nur 1 Buchstabe lang sein und die Groß-/Kleinschreibung muss auch stimmen. So kommt man auf insgesamt 52 mögliche Zeichen.

Danke
Bitte

LG
Oliver

Gruß
@Snowman25