The argument list that you showed above is not correct either because white space separates arguments, so for example
--info Prueft den Status
will be understood as 4 different argument, a value Prueft for the option --info and two separate arguments 'den' and 'Status'. Similarly
--eventtime 2022-03-16 09:13:42 +0100
will not be correctly parsed because it contains spaces. The correct way to pass this argument would be by quoting the values containing white space characters:
Output:
--info "Prueft den Status wichtiger Windows-Services auf Windows-Hosts" --IPAddress 99.99.99.99 --host ccccccccc0416 --eventtime "2022-03-16 09:13:42 +0100"
radioactive9 Wrote:How come the 2 scripts getting two different arguments even if they are called exactly under same configuration
We can't tell because we don't have the complete code of the scripts to analyse what they do. I suggest that you stay with a Python script and don't mix that with a shell script, which introduces even more language complexity in the problem. Your main issue is that you don't yet master the basics of Python. Have you tried producing the argument list with the code I wrote above?
I was so frustrated I even tried to use docopt - but it is too complex and I left the idea
Then taking your line of thought I removed all the parameters which was being passed from the Tool whose value contains space

And voila. It just went through and created the necessary servicenow ticket.
Yes I am absolute noob in python. I know this and that in all coding language - but not mastered any of them.
For example -
I passed all single worded value arguments and all went well
As soon as I introduced --os which has space it stopped working as the value has space.
Further to my testing '--eventtime', '2022-03-16 16:15:16 +0100' actually pursing without any issue. But --os fails :(
So what are my options as --output is very crucial parameter which contain important information and need to be part of the ticket.
(Mar-16-2022, 08:55 AM)Gribouillis Wrote: [ -> ]Have you tried producing the argument list with the code I wrote above?
No I kept getting Error to run that. Those oneliners always confuse me.
Gribouillis Wrote:The correct way to pass this argument would be BY QUOTING THE VALUES CONTAINING WHITE SPACE characters:
Output:
--info "Prueft den Status wichtiger Windows-Services auf Windows-Hosts" --IPAddress 99.99.99.99 --host ccccccccc0416 --eventtime "2022-03-16 09:13:42 +0100"
The same applies to
--os "Windows Server 2016 Standard"
Wikipedia: Quotation Mark
(Mar-16-2022, 02:34 PM)radioactive9 Wrote: [ -> ]Further to my testing '--eventtime', '2022-03-16 16:15:16 +0100' actually pursing without any issue. But --os fails :(
Even though --eventtime has space but it goes through without problem and double quotes.
I figured out a way to pass '--os', ' "Windows Server 2016 Standard" ' - but it continues to fail
I couldn't run your code

and I know that could have helped a lot.

Please help me to dump the exact arguments in the debug log.
radioactive9 Wrote:I figured out a way to pass '--os', ' "Windows Server 2016 Standard" ' - but it continues to fail
Don't pass
Output:
'--os', ' "Windows Server 2016 Standard" '
Instead pass
Output:
--os "Windows Server 2016 Standard"
Don't add commas and random quotation marks.
(Mar-16-2022, 03:46 PM)Gribouillis Wrote: [ -> ]radioactive9 Wrote:I figured out a way to pass '--os', ' "Windows Server 2016 Standard" ' - but it continues to fail
Don't pass
Output:
'--os', ' "Windows Server 2016 Standard" '
Instead pass
Output:
--os "Windows Server 2016 Standard"
Don't add commas and random quotation marks.
Hi I am not doing it. That is what is all confusing things. Exact argument passed by the tool is still elusive.
All I am doing is
logging.debug('Printing all arguments %s', sys.argv[1:])
output:
Quote:20921 2022-03-16 17:14:45 DEBUG - <module>: Printing all arguments ['--IPAddress', '00.00.00.00.', '--operatormw', 'RESP_APPL_GER', '--operatoros', 'MOBILITY_LINUX', '--division', 'Tech', '--environment', 'DEV', '--eventtime', '2022-03-16 17:14:45 +0100', '--host', 'treeofonion', '--host_appname', 'APP-RIA', '--notificationtype', 'PROBLEM', '--operator', 'operator_os', '--os', '"Red Hat Enterprise Linux 6"', '--priority', 'WARNING', '--service', 'SN-LIN-disk-slash']
And the output in the log is coming as that with comma all over the place and I do not know why.
Even though it is the same
If I remove --os from the tool the same output is working. If I introduce --os in the tool and pass it as argument it doesn't work.
Also I tried to strip the "," but it seems the output in the debug log still has the commas. So not sure exactly what tool is passing and what python is capturing.
Remember when I use a shell script exactly the same way it doesn't have those commas which i have shared earlier.
So now the most important thing is how to dump the arguments as the above code is introducing commas which seems to be not correct
radioactive9 Wrote:So now the most important thing is how to dump the arguments as the above code is introducing commas which seems to be not correct
I already told you how to dump the arguments (assuming your version of Python is at least 3.6)
print('Printing all arguments', ' '.join(f'"{a}"' if ' ' in a else a for a in sys.argv[1:]))
I'm afraid I cannot give more help than this line (which must work)
@
radioactive9
This thread has gone on way too long and I think that is due to poor communication. It is very important that you be thorough when describing what you are doing and what you are asking.
This is not a valid command line argument.
Quote:'--os', ' "Windows Server 2016 Standard" '
This is valid.
Quote:--os "Windows Server 2016 Standard"
If you are using the valid command line argument format, do not report you are using the invalid format. Use block quotes like above if you feel the need to for "quoting" your code snippits.
Your questions are vague. Instead of something like this:
Quote:I couldn't run your code Huh and I know that could have helped a lot.
Be sure that you reference what you are talking about.
Quote:I cannot run this code: print('Printing all arguments', ' '.join(f'"{a}"' if ' ' in a else a for a in sys.argv[1:]))
It generates this error:
Error:
Traceback (most recent call last):
File "...y", line 1, in <module>
print('Printing all arguments', ' '.join(f'"{a}"' if ' ' in a else a for a in sys.argv[1:]))
NameError: name 'sys' is not defined
(Mar-16-2022, 04:14 PM)Gribouillis Wrote: [ -> ]radioactive9 Wrote:So now the most important thing is how to dump the arguments as the above code is introducing commas which seems to be not correct
I already told you how to dump the arguments (assuming your version of Python is at least 3.6)
print('Printing all arguments', ' '.join(f'"{a}"' if ' ' in a else a for a in sys.argv[1:]))
I'm afraid I cannot give more help than this line (which must work)
Version is lower: Does that causing the problem ?
Python 3.4.10
f" string formatting is new in Python 3.6. You need to do this:
print('Printing all arguments', ' '.join('"{}"'.format(a) if ' ' in a else a for a in sys.argv[1:]))