I have following 2 commands in powershell script file, but second command did not wait till first command gets executed.
cmd.exe /c "msiexec /i c:\Temp\mysql.msi /quiet"
cd "C:\Program Files (x86)\MySQL\MySQL Installer for Windows"
note: first command installing mysql installer at location C:\Program Files (x86)\MySQL\MySQL Installer for Windows"...
In second command, i used cd to go to at directory C:\Program Files (x86)\MySQL\MySQL Installer for Windows"
Your PowerShell script does not know what the cmd.exe command is going to execute but it does wait for cmd.exe to finish.
The problem is that cmd.exe is not waiting for msiexec before returning.
If you wish to wait for msiexec to finish before moving on to your second command then call msiexec yourself using Start-Process with the -Wait parameter:
Start-Process -Wait -FilePath msiexec -ArgumentList "/i c:\Temp\mysql.msi /quiet"
Related
To start a MySQL (technically mariadb) module from the XAMPP control panel, you just click the "Start" action button. What command is being run behind the scenes for "Start"? I've tried to replicate it from the command line with a variety of commands, but I've found that the "Start" button will succeed where my command-line commands fail.
The net start and net stop commands from a command line will start and stop services including of course MySQL or MariaDB.
net start mariadb
basically
mysqld.exe --defaults-file="C:\ammpp\my.ini"
mysqld is the server command
the my.ini ist the configuration you have to check the folder
And MySQL80 is the name
see manual for more options
As the github says is the command line in the batch file xampp/mysql_start.bat `
mysql\bin\mysqld --defaults-file=mysql\bin\my.ini --standalone --console
the my.ini makes some minor changes to the default values, no trickery at all
I have no idea what trickery the XAMPP package uses, but if you want to start the mariadb service from the cmd, all you need is an elevated command prompt and the following line:
net start MariaDB
Note: my OS is Win10
A modification of nbk's answer worked for me in PowerShell:
C:\xampp\mysql\bin\mysqld.exe --defaults-file="C:\xampp\mysql\bin\my.ini" --console
This shows up as running in the XAMPP Control Panel (v3.2.4) and uses the correct port from the my.ini file (I'm using port 3308).
To stop the MySQL server, you can hit Ctrl+C, but only if the MySQL server is open with the --console param. To stop it from another terminal I've tried various shutdown commands, but none have worked for me so I've had to use the ugly command:
taskkill /FI "IMAGENAME eq mysqld.exe" /T /F
From a .bat batch file I've also found these commands useful for starting and stopping:
:: Start
start "XamppMySQLD1" powershell -NoExit -command "& 'C:\xampp\mysql\bin\mysqld.exe' --defaults-file='C:\xampp\mysql\bin\my.ini' --console" || echo ERROR && exit /b
:: Is it running? On the expected port?
tasklist | findstr /i "mysql"
netstat -ano | findstr 3308
:: Stop
taskkill /FI "WindowTitle eq XamppMySQLD*" /T /F
When running this from command line as root it works
unoconv -f csv $file
But when running it as www-data this error is returned
Traceback (most recent call last):
File "/usr/bin/unoconv", line 1114, in <module>
office_environ(of)
File "/usr/bin/unoconv", line 203, in office_environ
os.environ['PATH'] = realpath(office.basepath, 'program') + os.pathsep + os.environ['PATH']
File "/usr/lib/python3.4/os.py", line 633, in __getitem__
raise KeyError(key) from None
KeyError: 'PATH'
update
echo shell_exec('echo $PATH');
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
centos 7.3 with php via php-fpm
the env in php is cleaned by php-fpm
u can use putenv to set evn["PATH"] in php code, examples
putenv("PATH=/sbin:/bin:/usr/sbin:/usr/bin");
var_dump(shell_exec('unoconv -vvvv -f pdf -o 123.pdf 123.doc));
or u can set env use one line shell cmd
var_dump(shell_exec('PATH=/sbin:/bin:/usr/sbin:/usr/bin'.' unoconv -vvvv -f pdf -o 123.pdf 123.doc));
or u can change /etc/php-fpm.d/www.conf to pass the env to php, add this line
clean_env = no
and the restart php-fpm
systemctl restart php-fpm.service
The PHP call you used (pasted from chat):
exec("unoconv -f csv $file")
My guess is that exec() is giving you an environment that is too limited. To work around this, you could set up a polled directory. The PHP script would copy files to be converted into the polled directory and wait for the files to be converted.
Then create a bash script (either running as root or a somewhat more secure user) to run in an infinite loop and check the polled directory for any incoming files. See How to keep polling file in a directory till it arrives in Unix for what the bash script might look like.
When the bash script sees incoming files, it runs unoconv.
Found a solution myself by running libreoffice directly
sudo libreoffice --headless --convert-to csv --outdir $tmp_path $file
I'm trying it write a window batch file to perform several tasks in series, However, it always stops after tie first command in the script.
I am use this this batch file code:
start cmd /k cd %CD%mysql\bin && mysqld --install
I want to use this batch file command and install the MySQL but it run only only one command
You have the following command in your batch file:
start cmd /k cd %CD%mysql\bin && mysqld --install
Lets break it down into smaller pieces.
start start a program, command or batch script (opens in a new window.)
cmd /k cd %CD%mysql\bin run `cd %CD%mysql\bin and then return to the cmd prompt.
&& if the above succeeds then run the next command
mysqld --install run mysqld --install if start cmd /k cd %CD%mysql\bin succeeded
The second part will never run as the first part returned to the command prompt.
Try the following batch file instead:
cd %CD%mysql\bin
mysqld --install
Note the variable CD must be assigned a sensible value, otherwise cd %CD%mysql\bin will fail.
Seems you have a lot of layers here: both start and cmd /c (which I think you'd prefer over cmd /k for use in a batch file).
What's wrong with just cd %CD%\mysql\bin && mysqld --install? This worked fine for me when I attempted to run notepad.exe thus: cd /d %WINDIR%\System32 && notepad (note the additional '\' character here, just in case ... an extra backslash won't hurt if env var CD already has one). For that matter, I'll bet %CD%\mysql\bin\mysqld --install would work just fine.
However, just in case you want the extra cruft – or, more likely, need it for some other functionality you're not showing. Using just cmd:
cmd /c "cd %CD%\mysql\bin && mysqld --install"
using just start:
start "" "cd %CD%\mysql\bin && mysqld --install"
I'd put a solution using both start and cmd, but you just don't need it.
BTW, if you can't just call %CD%\mysql\bin\mysqld --install directly, I'd look into using pushd instead of cd, so that you can call popd at the end of your overall script ... it's just good form to put your script user back in the directory in which they started.
I am using below code to install mysql silently on windows using a batch file..
Seems like it is ignoring /qn
also i have tried with /quiet but that is also not working.
it is just reading line and moving cursor to next line.
echo off
cls
echo Starting MySQL mysql-essential-5.0.88-win32 install
msiexec /i "mysql-essential-5.0.88-win32.msi" /qn INSTALLDIR="C:\Program Files\MySQL" /L* "C:\Program Files\MySQL\mysql-log.txt"
echo MySQL mysql-essential-5.0.88-win32 installed successfully
echo Creating MySQL Windows service
"C:\Program Files\MySQL\bin\mysqlinstanceconfig.exe" -i -q ServiceName="MySQL service" RootPassword="newRootPassword" ServerType=SERVER DatabaseType=MYISAM Port=3306
RootCurrentPassword=mysql
echo MySQL Instance Configured. Service started.
pause
I have tried directly running command but it is completely ignoring
NOTE: Setup is working fine if i run it directly, issue is with silent installation only
please suggest.
thanks.
/ni
/q
/qn
/quiet
/s
/silent
Try dashes instead of forward slashes too (-S instead of /S), and check both upper case and lower case.
Hope that helps.
#Echo off
FOR /F "tokens=5" %%a in ('netstat -aon ^| find "3306" ^| find "LISTENING"') do taskkill /f /pid %%a
cls
TIMEOUT 1
if "%ProgramFiles(x86)%" == "" (
set "MySQLServerPath=%ProgramFiles%\MySQL\MySQL Server 5.0\bin"
) else (
set "MySQLServerPath=%ProgramFiles(x86)%\MySQL\MySQL Server 5.0\bin"
)
REM echo Configurating MySQL Server ...
"%MySQLServerPath%\MySQLInstanceConfig.exe" -i -q ServerType=DEVELOPER ConnectionUsage=DSS Port=3306 StrictMode=yes Charset=utf8 DatabaseType=MIXED ServiceName=root RootPassword=root
REM echo MySQL has been configured successfully.
I have been looking on information about exec cmd.exe, but I cannot find anything helpful. Can anyone explain to me the following code:
exec cmd.exe /c start /wait $buildLoc\\setup.exe /extract_all:C:/setup
Let's break it down:
exec cmd.exe /c start /wait $buildLoc\\setup.exe /extract_all:C:/setup
#^^^
The exec command starts a subprocess.
exec cmd.exe /c start /wait $buildLoc\\setup.exe /extract_all:C:/setup
# ^^^^^^^^^^
cmd.exe is a windows "batch" shell, The /c flag asks it to run its arguments as a command.
exec cmd.exe /c start /wait $buildLoc\\setup.exe /extract_all:C:/setup
# ^^^^^^^^^^^
The start command, built into cmd.exe, is also a way to get another program to start. The /wait flag tells it to wait until the started program ends.
exec cmd.exe /c start /wait $buildLoc\\setup.exe /extract_all:C:/setup
# ^^^^^^^^^
A regular TCL variable; it will be expanded inside TCL.
The rest is whatever the setup.exe program does (which is who knows what...)
Without knowing a little more about the program being run here (see below) it's hard to say exactly why the intermediate exec.cmd /c start /wait was needed; I'd guess that the cmd.exe is to load all of the system's default environment (instead of using the environment inherited from the tcl program) and the start is to open a terminal window so the output of the setup.exe program is shown to the user.
Check out auto_execok
exec {*}[auto_execok start] /wait $buildLoc\\setup.exe /extract_all:C:\\setup