Problem mit If Schleife Vergleich

Seelenschnitter
Beiträge: 13
Registriert: 14 Apr 2022, 14:27

Problem mit If Schleife Vergleich

Beitrag von Seelenschnitter »

Hallo zusammen,

ich bin geraqde an einem Script beschäftigt, welches mich etwas kirre macht:

Ich habe eine String Liste, die mit Werten aus GetProductPropertyList gefüllt wird. Danach kommt nach einer for Schleife ein Vergleich. Dieser funktioniert aber nicht. Er hat gestern einmal funktioniert und hörte dann einfach heute wieder auf.

Code: Alles auswählen

DefStringList $sprache$

set $sprache$ = createStringList("ESOffice2019")
set $sprache$ = GetProductPropertyList("sprachen",$sprache$)

set $sprache1$ = "ESOffice2019"
set $sprache2$ = "ESOffice2021"
set $sprache3$ = "NLOffice2019"
set $sprache4$ = "NLOffice2021"

for %s% in $sprache$ do sub_sprache 

[sub_sprache]
if ('$sprache$' = '$sprache1$')
	winbatch_office_ES2019
else
	if ('$sprache$' = '$sprache2$')
	  winbatch_office_ES2021
else
	   if ('$sprache$' = '$sprache3$')
		winbatch_office_NL2019
else
	  if ('$sprache$' = '$sprache4$')
		winbatch_office_NL2021
       endif
      endif
    endif
endif
Hier gebe ich einen default Wert mit, da ich es lokal teste und es ja keine Verbindung zum opsi-configed gibt.
Danach soll er prüfen wenn der Wert aus der stringliste $sprache$ = X ist soll er eine Subsection asuführen, welche in der sections.opsiinc weiter definiert ist. Ebenso sind sämtliche Variablen in der declarations.opsiinc initialisiert.

Das Log äußert sich nun wie folgt im oberen Beispiel:

Code: Alles auswählen

  The value of the variable "$sprache$" is now:
[7] [2024-03-13 13:16:16.363] []   (string   0)ESOffice2019
[7] [2024-03-13 13:16:16.377] [] No service connection in GetProductPropertyList - using default
[7] [2024-03-13 13:16:16.389] []   The value of the variable "$sprache$" is now:
[7] [2024-03-13 13:16:16.403] []   (string   0)ESOffice2019
[6] [2024-03-13 13:16:16.417] []   The value of the variable "$sprache1$" is now: "ESOffice2019"
[6] [2024-03-13 13:16:16.428] []   The value of the variable "$sprache2$" is now: "ESOffice2021"
[6] [2024-03-13 13:16:16.442] []   The value of the variable "$sprache3$" is now: "NLOffice2019"
[6] [2024-03-13 13:16:16.455] []   The value of the variable "$sprache4$" is now: "NLOffice2021"
[6] [2024-03-13 13:16:16.469] [] 
[6] [2024-03-13 13:16:16.483] [] ~~~~~~ Looping through:  'ESOffice2019'
[6] [2024-03-13 13:16:16.496] []   
[6] [2024-03-13 13:16:16.510] []   ~~~~~~~ Start Sub ~~~~~~~  sub_sprache
[6] [2024-03-13 13:16:16.524] []   If
[7] [2024-03-13 13:16:16.538] []   '$sprache$' = '$sprache1$'   <<< result false
[6] [2024-03-13 13:16:16.550] []   ('$sprache$' = '$sprache1$')   <<< result false
[6] [2024-03-13 13:16:16.563] [] Then
[6] [2024-03-13 13:16:16.579] [] Else
[6] [2024-03-13 13:16:16.594] []   If
[7] [2024-03-13 13:16:16.610] []     '$sprache$' = '$sprache2$'   <<< result false
[6] [2024-03-13 13:16:16.624] []     ('$sprache$' = '$sprache2$')   <<< result false
[6] [2024-03-13 13:16:16.637] []   Then
[6] [2024-03-13 13:16:16.652] []   Else
[6] [2024-03-13 13:16:16.664] []     If
[7] [2024-03-13 13:16:16.680] []       '$sprache$' = '$sprache3$'   <<< result false
[6] [2024-03-13 13:16:16.694] []       ('$sprache$' = '$sprache3$')   <<< result false
[6] [2024-03-13 13:16:16.708] []     Then
[6] [2024-03-13 13:16:16.723] []     Else
[6] [2024-03-13 13:16:16.738] []       If
[7] [2024-03-13 13:16:16.752] []         '$sprache$' = '$sprache4$'   <<< result false
[6] [2024-03-13 13:16:16.765] []         ('$sprache$' = '$sprache4$')   <<< result false
[6] [2024-03-13 13:16:16.780] []       Then
[6] [2024-03-13 13:16:16.814] []       EndIf
[6] [2024-03-13 13:16:16.830] []     EndIf
[6] [2024-03-13 13:16:16.844] []   EndIf
[6] [2024-03-13 13:16:16.858] [] EndIf
Wie man sieht ist eigentlich die Variable $sprache$ mit "ESOffice2019" gefüllt und $sprache1$ mit "ESOffice2019". Trotz allem gibt er "result false" aus.

Führe ich das Script so aus:

Code: Alles auswählen

DefStringList $sprache$

set $sprache$ = createStringList("ESOffice2019")
set $sprache$ = GetProductPropertyList("sprachen",$sprache$)
;set $sprache1$ = "ESOffice2019"
;set $sprache2$ = "ESOffice2021"
;set $sprache3$ = "NLOffice2019"
;set $sprache4$ = "NLOffice2021"

for %s% in $sprache$ do sub_sprache 

[sub_sprache]
if ('$sprache$' = "ESOffice2019")
	winbatch_office_ES2019
else
	if ('$sprache$' = "ESOffice2021")
	  winbatch_office_ES2021
else
	   if ('$sprache$' = "NLOffice2019")
		winbatch_office_NL2019
else
	  if ('$sprache$' = "NLOffice2021")
		winbatch_office_NL2021
       endif
      endif
    endif
endif
Ist das Ergebnis gleich:

Code: Alles auswählen

 defined global string list $sprache$
[7] [2024-03-13 13:18:49.148] []   The value of the variable "$sprache$" is now:
[7] [2024-03-13 13:18:49.160] []   (string   0)ESOffice2019
[7] [2024-03-13 13:18:49.175] [] No service connection in GetProductPropertyList - using default
[7] [2024-03-13 13:18:49.189] []   The value of the variable "$sprache$" is now:
[7] [2024-03-13 13:18:49.205] []   (string   0)ESOffice2019
[6] [2024-03-13 13:18:49.216] [] 
[6] [2024-03-13 13:18:49.231] [] ~~~~~~ Looping through:  'ESOffice2019'
[6] [2024-03-13 13:18:49.245] []   
[6] [2024-03-13 13:18:49.257] []   ~~~~~~~ Start Sub ~~~~~~~  sub_sprache
[6] [2024-03-13 13:18:49.274] []   If
[7] [2024-03-13 13:18:49.289] []   '$sprache$' = "ESOffice2019"   <<< result false
[6] [2024-03-13 13:18:49.303] []   ('$sprache$' = "ESOffice2019")   <<< result false
[6] [2024-03-13 13:18:49.329] [] Then
[6] [2024-03-13 13:18:49.343] [] Else
[6] [2024-03-13 13:18:49.359] []   If
[7] [2024-03-13 13:18:49.375] []     '$sprache$' = "ESOffice2021"   <<< result false
[6] [2024-03-13 13:18:49.389] []     ('$sprache$' = "ESOffice2021")   <<< result false
[6] [2024-03-13 13:18:49.404] []   Then
[6] [2024-03-13 13:18:49.416] []   Else
[6] [2024-03-13 13:18:49.429] []     If
[7] [2024-03-13 13:18:49.445] []       '$sprache$' = "NLOffice2019"   <<< result false
[6] [2024-03-13 13:18:49.458] []       ('$sprache$' = "NLOffice2019")   <<< result false
[6] [2024-03-13 13:18:49.473] []     Then
[6] [2024-03-13 13:18:49.488] []     Else
[6] [2024-03-13 13:18:49.500] []       If
[7] [2024-03-13 13:18:49.514] []         '$sprache$' = "NLOffice2021"   <<< result false
[6] [2024-03-13 13:18:49.527] []         ('$sprache$' = "NLOffice2021")   <<< result false
[6] [2024-03-13 13:18:49.560] []       Then
[6] [2024-03-13 13:18:49.568] []       EndIf
[6] [2024-03-13 13:18:49.582] []     EndIf
[6] [2024-03-13 13:18:49.595] []   EndIf
[6] [2024-03-13 13:18:49.608] [] EndIf
Führe ich das Script nun aber so geschrieben aus, wie sämtliche Beispiele aus der Doku

Code: Alles auswählen

if ($ConstTest$ = $CompValue$)
		comment "passed"
	else
ohne die Anführungszeichen in den Variablen:

Code: Alles auswählen

DefStringList $sprache$

set $sprache$ = createStringList("ESOffice2019")
set $sprache$ = GetProductPropertyList("sprachen",$sprache$)
set $sprache1$ = "ESOffice2019"
set $sprache2$ = "ESOffice2021"
set $sprache3$ = "NLOffice2019"
set $sprache4$ = "NLOffice2021"

for %s% in $sprache$ do sub_sprache 

[sub_sprache]
if ($sprache$ = $sprache1$)
	winbatch_office_ES2019
else
	if ($sprache$ = $sprache2$)
	  winbatch_office_ES2021
else
	   if ($sprache$ = $sprache3$)
		winbatch_office_NL2019
else
	  if ($sprache$ = $sprache4$)
		winbatch_office_NL2021
       endif
      endif
    endif
endif
klappt garnichts mehr:

Code: Alles auswählen

 No service connection in GetProductPropertyList - using default
[7] [2024-03-13 13:23:21.768] []   The value of the variable "$sprache$" is now:
[7] [2024-03-13 13:23:21.782] []   (string   0)ESOffice2019
[6] [2024-03-13 13:23:21.796] []   The value of the variable "$sprache1$" is now: "ESOffice2019"
[6] [2024-03-13 13:23:21.809] []   The value of the variable "$sprache2$" is now: "ESOffice2021"
[6] [2024-03-13 13:23:21.821] []   The value of the variable "$sprache3$" is now: "NLOffice2019"
[6] [2024-03-13 13:23:21.836] []   The value of the variable "$sprache4$" is now: "NLOffice2021"
[6] [2024-03-13 13:23:21.849] [] 
[6] [2024-03-13 13:23:21.864] [] ~~~~~~ Looping through:  'ESOffice2019'
[6] [2024-03-13 13:23:21.879] []   
[6] [2024-03-13 13:23:21.893] []   ~~~~~~~ Start Sub ~~~~~~~  sub_sprache
[6] [2024-03-13 13:23:21.905] []   If
[7] [2024-03-13 13:23:21.919] []       <<< syntax error, no result!! - set to false
[6] [2024-03-13 13:23:21.935] []   (    <<< syntax error, no result!! - set to false
[2] [2024-03-13 13:23:21.950] []   Syntax Error in Section: sub_sprache (Command in line 73 in section: sub_sprache; file: setup.opsiscript; section start at line: 72; origin: setup.opsiscript; line: 73): ($sprache$ = $sprache1$) -> "$sprache$ = $sprache1$)" is an illegal String Expressionstr
[2] [2024-03-13 13:23:21.962] []   Syntax Error found in line: >if ($sprache$ = $sprache1$)<
[2] [2024-03-13 13:23:21.976] []   Syntax Error in Section: sub_sprache (Command in line 73 in section: sub_sprache; file: setup.opsiscript; section start at line: 72; origin: setup.opsiscript; line: 73): $sprache$ = $sprache1$) -> erroneous characters
[2] [2024-03-13 13:23:21.989] []   Syntax Error found in line: >if ($sprache$ = $sprache1$)<
[6] [2024-03-13 13:23:22.002] [] Then
[2] [2024-03-13 13:23:22.017] []   Syntax Error in Section: sub_sprache (Command in line 74 in section: sub_sprache; file: setup.opsiscript; section start at line: 72; origin: setup.opsiscript; line: 74): EndIf -> expected
[2] [2024-03-13 13:23:22.033] []   Syntax Error found in line: >winbatch_office_ES2019<
[6] [2024-03-13 13:23:22.069] []   
[6] [2024-03-13 13:23:22.080] []   ~~~~~~~ End Sub   ~~~~~~~  sub_sprache
[6] [2024-03-13 13:23:22.105] []   
[6] [2024-03-13 13:23:22.118] [] 
[6] [2024-03-13 13:23:22.132] [] ~~~~~~ End Loop

Wo mache ich einen Fehler?
Benutzeravatar
j.werner
uib-Team
Beiträge: 64
Registriert: 08 Okt 2019, 13:32

Re: Problem mit If Schleife Vergleich

Beitrag von j.werner »

Hallo,

Code: Alles auswählen

if ('%s%' = $sprache1$) 
...
elseif ('%s%' = $sprache2$) 
...
endif
sollte es tun.
Seelenschnitter
Beiträge: 13
Registriert: 14 Apr 2022, 14:27

Re: Problem mit If Schleife Vergleich

Beitrag von Seelenschnitter »

Hi,

das war gestern meine Lösung und auch das: result false

Ich hab diese Katastrophe aus Variablen nur gebaut, weil das alles immer wieder false zurück gab. Knackt es da denn irgendwo bei der Loopabfrage oder so? Weil wenn ich blank das in opsi_script teste:

Code: Alles auswählen

[Actions]

DefVar $Test1$
DefVar $Test2$

Set $Test1$ = "Tolle"
Set $Test2$ = "Wurst"



if ($Test1$ = "Tolle")
	comment "Wurstwasser"
if ($Test2$ = "Wurst")
	comment "Juhu"
    endif
endif

[6] [2024-03-13 14:28:54.415] []   The value of the variable "$Test1$" is now: "Tolle"
[6] [2024-03-13 14:28:54.427] []   The value of the variable "$Test2$" is now: "Wurst"
[6] [2024-03-13 14:28:54.436] [] If
[7] [2024-03-13 14:28:54.450] []   $Test1$ = "Tolle"   <<< result true
[6] [2024-03-13 14:28:54.460] []   ($Test1$ = "Tolle")   <<< result true
[6] [2024-03-13 14:28:54.471] [] Then
[5] [2024-03-13 14:28:54.485] []   comment: Wurstwasser
[6] [2024-03-13 14:28:54.496] []   If
[7] [2024-03-13 14:28:54.508] []     $Test2$ = "Wurst"   <<< result true
[6] [2024-03-13 14:28:54.517] []     ($Test2$ = "Wurst")   <<< result true
[6] [2024-03-13 14:28:54.530] []   Then
[5] [2024-03-13 14:28:54.543] []     comment: Juhu
[6] [2024-03-13 14:28:54.552] []   EndIf
[6] [2024-03-13 14:28:54.564] [] EndIf
Klappt wie gewünscht. Darf man nach einem for do Loop keine subsection ausführen oder so?

Ok dein Vorschlag klappt, wenn ich dafür keine for %s%.... drin habe. Allerdings frage ich mich dann weiterhin: Wieso?

Nachtrag: Mir kommt es so vor, als wenn eine Subsection gar keine if Abfragen ausführen kann. Richtig?
Benutzeravatar
SisterOfMercy
Beiträge: 1524
Registriert: 22 Jun 2012, 19:18

Re: Problem mit If Schleife Vergleich

Beitrag von SisterOfMercy »

You are comparing a StringList with a String. This is probably causing the syntax error.

I think you need one of the functions here: https://docs.opsi.org/opsi-docs-en/4.3/ ... -transform
For instance, the getSubListByContaining function. If there is a match, one can run the section. Something like this:

Code: Alles auswählen

Set $list$ = getListContaining($sprache$,$sprache1$)

if (count($list$) = "0")
    comment "No match found"
else
    winbatch_office_ES2019 /64bit
endif
Bitte schreiben Sie Deutsch, when I'm responding in the German-speaking part of the forum!
Benutzeravatar
wolfbardo
uib-Team
Beiträge: 1354
Registriert: 01 Jul 2008, 12:10

Re: Problem mit If Schleife Vergleich

Beitrag von wolfbardo »

Da scheint mir einiges durcheinander und ich erlaube mir Werbung zu machen für

https://www.uib.de/de/produkte/update-a ... ick-to-run

oder eine Script Schulung oder Support...

Warum werden im Script Stringlisten verwendet?

Code: Alles auswählen

if ('$sprache$' = '$sprache1$')
liefert immer false.

Gemeint ist wohl

Code: Alles auswählen

if ($sprache$ = $sprache1$)
Gruss
Bardo Wolf


OPSICONF 2024
https://opsi.org/en/opsiconf/

Basisworkshop Mainz :

17. - 20. 06. 2024


opsi support - uib gmbh
For productive opsi installations we recommend maintainance + support contracts which are the base of opsi development.

http://www.uib.de
Seelenschnitter
Beiträge: 13
Registriert: 14 Apr 2022, 14:27

Re: Problem mit If Schleife Vergleich

Beitrag von Seelenschnitter »

Hi Bardo,

darfst du gerne. Wir haben diesen Support Vertrag aber ich möchte diesen nicht nutzen, sondern selber aufgrund der Masse an Anfragen mich mehr warm machen damit. Wegen der Script Schulung denke ich gerne mal drüber nach. wir hatten damals in Kamp-Lintfort die allgemeine Schulung von uib wegen allgemeiner Bedienung von OPSI.

Die Idee war ein extra Packet mit Sprachen x,y,z zu haben und via multivalue halt zu installieren, was ausgewählt wurde.

wie oben ja ersichtlich habe ich ja

Code: Alles auswählen

if ($sprache$ = $sprache1$)
getestet.

Aber da will die Subsection wohl nicht.

@SisterOfMercy (nice music btw)
Comapring a stringlist with a string seems no to be a problem reffering to the opsi reference card or i missread something.
I first splitted my string and took it from 0 to 3 but it doesn't help, when your multivalue on String 0 can be a random value from the multivalue list in opsi-configed.
Benutzeravatar
SisterOfMercy
Beiträge: 1524
Registriert: 22 Jun 2012, 19:18

Re: Problem mit If Schleife Vergleich

Beitrag von SisterOfMercy »

Seelenschnitter hat geschrieben: 13 Mär 2024, 15:28 Comapring a stringlist with a string seems no to be a problem reffering to the opsi reference card or i missread something.
I first splitted my string and took it from 0 to 3 but it doesn't help, when your multivalue on String 0 can be a random value from the multivalue list in opsi-configed.
You might be able to compare them, but I'm not sure. At least it will always end up being false.
That's why I said to use one of the stringlist functions.
Bitte schreiben Sie Deutsch, when I'm responding in the German-speaking part of the forum!
Seelenschnitter
Beiträge: 13
Registriert: 14 Apr 2022, 14:27

Re: Problem mit If Schleife Vergleich

Beitrag von Seelenschnitter »

SisterOfMercy hat geschrieben: 13 Mär 2024, 16:20
Seelenschnitter hat geschrieben: 13 Mär 2024, 15:28 Comapring a stringlist with a string seems no to be a problem reffering to the opsi reference card or i missread something.
I first splitted my string and took it from 0 to 3 but it doesn't help, when your multivalue on String 0 can be a random value from the multivalue list in opsi-configed.
You might be able to compare them, but I'm not sure. At least it will always end up being false.
That's why I said to use one of the stringlist functions.
I used the solution of j.werner now it's doing his part now. Guess my mistake was to call the if loop in a subsection.
But my next idea to do the packet for office 2019 and one for 2021 while gatting a value from regedit which version is installed on the pc and then install the language packs.
Benutzeravatar
SisterOfMercy
Beiträge: 1524
Registriert: 22 Jun 2012, 19:18

Re: Problem mit If Schleife Vergleich

Beitrag von SisterOfMercy »

Seelenschnitter hat geschrieben: 13 Mär 2024, 16:56 I used the solution of j.werner now it's doing his part now. Guess my mistake was to call the if loop in a subsection.
But my next idea to do the packet for office 2019 and one for 2021 while gatting a value from regedit which version is installed on the pc and then install the language packs.
That is because %s% is now a string. It iterates over all entries in $sprache$ and compares each entry (a string) with another string. You should have j.werner's solution in a subsection.
Bitte schreiben Sie Deutsch, when I'm responding in the German-speaking part of the forum!
Seelenschnitter
Beiträge: 13
Registriert: 14 Apr 2022, 14:27

Re: Problem mit If Schleife Vergleich

Beitrag von Seelenschnitter »

SisterOfMercy hat geschrieben: 13 Mär 2024, 18:54
Seelenschnitter hat geschrieben: 13 Mär 2024, 16:56 I used the solution of j.werner now it's doing his part now. Guess my mistake was to call the if loop in a subsection.
But my next idea to do the packet for office 2019 and one for 2021 while gatting a value from regedit which version is installed on the pc and then install the language packs.
That is because %s% is now a string. It iterates over all entries in $sprache$ and compares each entry (a string) with another string. You should have j.werner's solution in a subsection.
Jeah thats why i set up the "for in do" i can get rid of it with adressing %s% directly entirely. I did the script new anyway now even after it worked. I now get the installed office version from registry, compare it and then install the language packs. So this can be closed.
Antworten