I'm stuck on a problem where I can't find a reasonable work around. I'm trying to run multiple commands in the Windows CMD from inside a C++ Program using
CreateProcessW(NULL,L"mysql -u root -ptoor && source C:\Users\IEUser\Documents\SWE-Software\Datenbank\datenbank-build.sql", ... );
The Problem is that when i run this code (or even when I manually put in the the CMD Window, that the second half of the command won't run since prior to this it changes the "instance?" of the CMD to that of the mysql executable.
How would I fix or work around this?
I know in python you can somewhat simulate typing in a way, which could potentially be a work around here.. But i prefer a simple solution without any external libraries.
EDIT: To clarify the first Command seems to run since I can literally see the new console text of the mysql command. Its just that the second command won't be copied in there. It just stays blank and waits for input.
EDIT: This is the Output I'm getting:
What I do want is this:
SOLUTION
you can run normal statements in cmd before e.g.set PATH=\%PATH\%;
then you would use an operator like &&
.
When you want to an mysql statement it has a special syntax we can use here:
mysql -u username -ppassword -e "ANY VALID MYSQL STATEMENT GOES IN HERE"
e.g.:
set PATH=\%PATH\%;C:\\mariadb\\bin && mysql -u root -ptoor -e "source C:\Users\IEUser\Documents\SWE-Software\Datenbank\datenbank-build.sql"
If you encounter problems with your cmd try adding an cmd /c
at the start of the whole statement.
Also if mysql statement fails replace the path code with a cd mariaspath\bin
, this made everything work for me.
FINAL CODE AS IT RAN IN CMD cmd /c set PATH=%PATH%;C:\Program Files\MariaDB 10.10\bin\ && mysql -u root -ptoor -e "source C:\Users\IEUser\Documents\SWE-Software\Datenbank\datenbank-build.sql" -q
(note that those were ofc not hard coded but obtained at runtime.