What i am trying to achieve is, query a database for a string, get the string and execute it on shell.
In my MySQL database, there is a column that holds the string value (varchar (1000))
I query it using db.SQLSelect, get the result in a recordset variable, then get the string value using the following code:
dim rs as RecordSet
rs = db.SQLSelect("SELECT * FROM A WHERE B = 0")
command = str(rs.Field("command").StringValue)
Then i want to execute this in shell but it doesn’t work. I can see the string is correct:
So if i change it to mode 1 and if i type it in quotes like s.execute(“notepad”) it works, however if i try to run it using the string it doesn’t. Could that have something to do with encoding? I mean i can see it’s typed correctly but…
Might there be an issue with something not trivial then having stored n0tepad instead of notepad in your database? Or more likely a carriage return or something else behind the word notepad, which is not shown while printing it to the console?
Can you output the value in Windows10 via a simple
MessageBox( command )
Perhaps the command is working, but you just don’t have the rights to execute it on this particular machine, as it is not running as an administrator? Then you could compile the app and then run the Programm in admin mode.
Or more likely a carriage return or something else behind the word notepad, which is not shown while printing it to the console?
My suggestion: using trim is okay if it works, but I would look at the root cause, you probably entered some special character in your database. Why do I suggest this? You are now sort of hiding an issue, via a command. That works, but it might cause you issues in the future and it is kind of “overdosed”.
string.trim is doing nothing else than removing leading and trailing whitespaces
It’s better to check your datasource and correct the issue there, it is nothing else than one or more “whitespaces”
Then, set up a timer to watch the dataAvailable event on the shell buffers and add their contents to your return data structure until the program terminates.
I use files to send & receive data to/from a python program and use an asynchronous shell because the program can run a half-hour or more on occasion but usually it’s a couple seconds. In this day and age of SSDs and fancy OS file-caching, using files can be surprisingly fast.