mysql-workbench, how do I write a bash file command as to launch and open a SQL script to a query tab? - mysql-workbench

mysql-workbench, how do I write a bash file command as to launch and open a SQL script to a query tab? I am not sure which parameter I need to pass.
thks
ps. Now I am on a Fedora 32. (kind of very late edit, sorry)

You should always specify which OS you are using.
Generally, you can start MySQL Workbench with various command line paramaters. One of them is --help (-help on Windows). This will give you the following list:
MySQLWorkbench [<options>] [<model file>]
Options:
--query [<connection>] Open a query tab to the named connection or prompt for it if none given
--admin <instance> Open a administration tab to the named instance
--upgrade-mysql-dbs Open a migration wizard tab
--model <model file> Open the given EER model file
--open <file> Open the given file at startup
--run <script> Execute the given code in default language for GRT shell
--run-python <script> Execute the given code in Python
--run-lua <script> Execute the given code in Lua
--migration Open the Migration Wizard tab
--quit-when-done Quit Workbench when the script is done
--log-to-stderr Also log to stderr
--help, -h Show command line options and exit
--log-level=<level> Valid levels are: error, warning, info, debug1, debug2, debug3
--verbose, -v Enable diagnostics output
--version Show Workbench version number and exit
(this is for OS X and Linux, Windows uses a single dash instead). For OS X you also have to use the direct call. So instead of:
open /Applications/MySQLWorkbench.app --args --help
which will not show you the parameters use:
/Applications/MySQLWorkbench.app/Contents/MacOS/MySQLWorkbench --help
To open a connection and load an SQL script file use the following parameters:
... --query "Localhost 5.6" --open /Data/Work/Data/Scripts/alter_test.sql
Again, on Windows use single dashes. For the query parameter use the name of a connection you have defined.

Related

Run Multiple VS code projects through batch file (in a single go)

I have so many projects I have to open during windows startup.
So I have created batch file to open them in vs code as following.
start cmd /C code C:\project1
start cmd /C code C:\Project2
start cmd /C code C:\ProjectN
I also need them to run. I have launch.json for each project. How do I execute them through batch file.
First, I suggest streamlining your batch file as follows:
for %%p in (C:\project1 C:\project2 C:\projectN) do code %%p
Each project will open in its own window, asynchronously - no need for start, and no need for cmd child processes (double-quote individual paths as needed).
Note: If you wanted to open all projects in a single window, using a single workspace, you could simply do:
code C:\project1 C:\project2 C:\projectN
As for your desire to launch the projects for debugging after opening, it seems that code, Visual Studio's CLI does not support this, at least as of v1.66.
This isn't too surprising, given that the focus of an editor/IDE is on editing code, not on running it.
As of v1.66, code -h reports the following options (as also documented in the link above):
C:\>code -h
Visual Studio Code 1.66.0
Usage: code [options][paths...]
To read from stdin, append '-' (e.g. 'ps aux | grep code | code -')
Options
-d --diff <file> <file> Compare two files with each other.
-a --add <folder> Add folder(s) to the last active window.
-g --goto <file:line[:character]> Open a file at the path on the specified
line and character position.
-n --new-window Force to open a new window.
-r --reuse-window Force to open a file or folder in an
already opened window.
-w --wait Wait for the files to be closed before
returning.
--locale <locale> The locale to use (e.g. en-US or zh-TW).
--user-data-dir <dir> Specifies the directory that user data is
kept in. Can be used to open multiple
distinct instances of Code.
-h --help Print usage.
Extensions Management
--extensions-dir <dir> Set the root path for extensions.
--list-extensions List the installed extensions.
--show-versions Show versions of installed extensions,
when using --list-extensions.
--category <category> Filters installed extensions by provided
category, when using --list-extensions.
--install-extension <ext-id | path> Installs or updates an extension. The
argument is either an extension id or a
path to a VSIX. The identifier of an
extension is '${publisher}.${name}'. Use
'--force' argument to update to latest
version. To install a specific version
provide '#${version}'. For example:
'vscode.csharp#1.2.3'.
--pre-release Installs the pre-release version of the
extension, when using
--install-extension
--uninstall-extension <ext-id> Uninstalls an extension.
--enable-proposed-api <ext-id> Enables proposed API features for
extensions. Can receive one or more
extension IDs to enable individually.
Troubleshooting
-v --version Print version.
--verbose Print verbose output (implies --wait).
--log <level> Log level to use. Default is 'info'. Allowed
values are 'critical', 'error', 'warn',
'info', 'debug', 'trace', 'off'.
-s --status Print process usage and diagnostics
information.
--prof-startup Run CPU profiler during startup.
--disable-extensions Disable all installed extensions.
--disable-extension <ext-id> Disable an extension.
--sync <on | off> Turn sync on or off.
--inspect-extensions <port> Allow debugging and profiling of extensions.
Check the developer tools for the connection
URI.
--inspect-brk-extensions <port> Allow debugging and profiling of extensions
with the extension host being paused after
start. Check the developer tools for the
connection URI.
--disable-gpu Disable GPU hardware acceleration.
--max-memory <memory> Max memory size for a window (in Mbytes).
--telemetry Shows all telemetry events which VS code
collects.
Originally I wanted to run all the projects in one go. Figured that vs code provides such functionality through multi-root workspaces (You will be also able to check all git changes in one place using this multi-root workspace).
We can run all the projects in one go with the workspace definition below where configurations are nothing but individual launch.json file's name field which you need to launch in vs code which are inside sub folders/projects (if name are same in multiple launch.json then you need to specify folder along with name. More details in link below.)
And place this workspace at root of all child projects. Open this workspace and hit F5, it will run all the projects as well in single go (having said that you have individual launch.json files for each project which you have mentioned in below workspace).
"compounds": [{
"name": "Launch Server & Client",
"configurations": [
"Launch Server",
{
"folder": "Web Client",
"name": "Launch Client"
},
{
"folder": "Desktop Client",
"name": "Launch Client"
}
]
}]
Source: https://code.visualstudio.com/docs/editor/multi-root-workspaces

I used the command (code. -r) in the cmd window, but what does -r mean? (vscode)

While watching the YouTube development video, I used the command (code . -r) in the cmd window in vscode. What is this function? vscode turned on, but what does -r mean?
The help says:
-r --reuse-window Force to open a file or folder in an already opened window.
Full help is available to you:
$ code -h
code 1.55.2
Usage: code [options][paths...]
To read from stdin, append '-' (e.g. 'ps aux | grep code | code -')
Options
-d --diff <file> <file> Compare two files with each other.
-a --add <folder> Add folder(s) to the last active window.
-g --goto <file:line[:character]> Open a file at the path on the specified line and character position.
-n --new-window Force to open a new window.
-r --reuse-window Force to open a file or folder in an already opened window.
-w --wait Wait for the files to be closed before returning.
--locale <locale> The locale to use (e.g. en-US or zh-TW).
-h --help Print usage.
Extensions Management
--list-extensions List the installed extensions.
--show-versions Show versions of installed extensions, when using
--list-extensions.
--category Filters installed extensions by provided category, when
using --list-extensions.
--install-extension <extension-id[#version] | path-to-vsix> Installs or updates the extension. The identifier of an
extension is always `${publisher}.${name}`. Use
`--force` argument to update to latest version. To
install a specific version provide `#${version}`. For
example: 'vscode.csharp#1.2.3'.
--uninstall-extension <extension-id> Uninstalls an extension.
--enable-proposed-api <extension-id> Enables proposed API features for extensions. Can receive
one or more extension IDs to enable individually.
Troubleshooting
-v --version Print version.
--verbose Print verbose output (implies --wait).
--log <level> Log level to use. Default is 'info'. Allowed values are 'critical', 'error',
'warn', 'info', 'debug', 'trace', 'off'.
-s --status Print process usage and diagnostics information.
--prof-startup Run CPU profiler during startup
--disable-extensions Disable all installed extensions.
--disable-extension <extension-id> Disable an extension.
--sync <on> <off> Turn sync on or off
--inspect-extensions <port> Allow debugging and profiling of extensions. Check the developer tools for the
connection URI.
--inspect-brk-extensions <port> Allow debugging and profiling of extensions with the extension host being paused
after start. Check the developer tools for the connection URI.
--disable-gpu Disable GPU hardware acceleration.
--max-memory Max memory size for a window (in Mbytes).
From the official documentation:
-r or --reuse-window Forces opening a file or folder in the last active window.
IE, it doesn't launches a new instance of VSC, but opens a new tab in the existing opened instance, if it exists.

Run command line via alias with zsh on MATLAB

I use the system/unix command on Matlab in order to run an external program via the command line. I want to execute it via an alias define in .zshrc on my computer. Unfortunately, the alias seems to be not available.
Example with ll
on a terminal: which ll gives ll: aliased to ls -lh
on Matlab: unix('ll') gives zsh:1: command not found: ll
I check if I used the right shell: unix('echo $SHELL') gives /usr/local/bin/zsh.
I have add setopt aliases in my .zshrc but it changes nothing. Is it possible to check which startup files is used when you open a non interactive shell?
The ~/.zshrc seems to be not loaded in the non interactive case. The solution consists in loaded aliases and added setopt aliases in ~/.zshenv. See this for instance.

Command line foward engineering using a .mwb file?

I need to be able to perform a forward engineering from a model located in a .mwb file. All of this from the command line as I would like to automate the process.
Can anyone please let me know if this is possible and if so how?
This is the output in the command line once you call WB with --help:
mysql-workbench [<options>] [<model file>]
Options:
--force-sw-render Force Xlib rendering
--force-opengl-render Force OpenGL rendering
--query <connection> Open a query tab to the named connection
--admin <instance> Open a administration tab to the named instance
--model <model file> Open the given EER model file
--script <script file> Execute the given Python or Lua script file
--run <script> Execute the given code in default language for GRT shell
--run-python <script> Execute the given code in Python
--run-lua <script> Execute the given code in Lua
--quit-when-done Quit Workbench when the script is done
--help, -h Show command line options and exit
--log-level=<level> Valid levels are: error, warning, info, debug1, debug2, debug3
--verbose Enable diagnostics output
--version Show Workbench version number and exit
I guess you can load your model using the --model option and then create an script that will perform the forward engineering and run it using the --run option and then instruct WB to exit once it finishes with the --quit-when-done option.
You can consult WB help to learn more about creating scripts as well as this guide.
You can actually automate this task with Python (or Lua) script - MySQL Workbench already has an interpreter under Scripting menu. Create a new script and use the stub:
# -*- coding: utf-8 -*-
import os
import grt
from grt.modules import DbMySQLFE
c = grt.root.wb.doc.physicalModels[0].catalog
DbMySQLFE.generateSQLCreateStatements(c, c.version, {
'GenerateDrops' : 1,
'GenerateSchemaDrops' : 1,
'OmitSchemata' : 1,
'GenerateUse' : 1
})
DbMySQLFE.generateSQLCreateStatements(c, c.version, {
DbMySQLFE.createScriptForCatalogObjects(os.path.dirname(grt.root.wb.docPath) + 'ddl.sql', c, {})
It does not actully run from command line, but I beleive you can run it with --run-script option.
This question is too old, but I found a project on github that make this, below the commands in cmd windows, and here the github repository and more linux sh file version.
Windows
#echo off
REM generate sql from mwb
REM usage: mwb2sql.bat {.mwb file} {output file}
SET WORKBENCH="C:\Program Files (x86)\MySQL\MySQL Workbench 6.0 CE\MySQLWorkbench.exe"
SET OUTPUT=%~f2
%WORKBENCH% ^
-open %~f1 ^
-run-python "import os;import grt;from grt.modules import DbMySQLFE as fe;c = grt.root.wb.doc.physicalModels[0].catalog;fe.generateSQLCreateStatements(c, c.version, {});fe.createScriptForCatalogObjects(os.getenv('OUTPUT'), c, {})" ^
-quit-when-done

Cygwin - run script silenty from "run command"

I have script lets say:
C:\foo.bsh
I want to be able to run this command via the windows run command:
Start -> Run
Windows Key + R
and type something small like 'foo' and hitting return.
However, I do not want a cmd prompt to be visible. This script does some preprocessing for an IDE. I do not want the cmd prompt to be open for the lifetime of the IDE process.
I have tried:
1) Creating a bat file with the following contents:
c:\cygwin\bin\bash --login "C:\foo.bsh" (this fails because it keeps a cmd open)
2) Converting the above bat file to an exe using bat_2_exe_converter (does not make the cmd silent)
thoughts?
EDIT: The solution so far suggests something to type from an actual cygwin shell. I am trying to get a faster solution by having something short I can type in the Windows run command. Also, the nohup command; exit doesn't automatically kill the box - however I can manually kill it without killing the IDE process. The run command accepts shortcuts (.lnk's), bat's, exe's.
Try the run.exe command of cygwin. It is a big install, a complete unix environment for your Windows machine. Suppose you installed it at c:\cygwin\.
No mystery, just run c:\cygwin\bin\run.exe <your command here> and you will have your no dos window execution.
You can run it from any DOS window (run cmd.exe from the start menu). You don't need to run it from cygwin.
To make it easier, append C:\cygwin\bin to your %PATH% env var (My Computer → Properties → Advanced → Environment Variables) (Kudos to Felipe Alvarez comment).
Now you can just type
c:\cygwin\bin\run.exe "C:\foo.bsh"
You must create a link in your Start Menu with this command so will be able to run it with Win-R.
Here is the man page of the runcommand:
$ man run
RUN(1) run 1.3.0 RUN(1)
NAME
run - start programs with hidden console window
SYNOPSIS
run [ -p path ] command [ -wait ] arguments
runcommand [ -p path ] [ -wait ] arguments
DESCRIPTION
Windows programs are either GUI programs or console programs. When
started console programs will either attach to an existing console
or create a new one. GUI programs can never attach to an exiting con‐
sole. There is no way to attach to an existing console but hide it if
started as GUI program.
run will do this for you. It works as intermediate and starts a pro‐
gram but makes the console window hidden.
With -p path you can add path to the PATH environment variable.
Issuing -wait as first program argument will make run wait for program
completition, otherwise it returns immediately.
The second variant is for creating wrappers. If the executable is
named runcommand (eg runemacs), run will try to start the program (eg
emacs).
EXAMPLES
run -p /usr/X11R6/bin xterm
run emacs -wait
runemacs -wait
run make -wait
AUTHORS
Charles S. Wilson
Harold L Hunt II
Jehan Bing
Alexander Gottwald
Version 1.3.0 November 2005 RUN(1)
You can use either...
c:\cygwin\bin\bash -l /path/to/script_to_interpret.sh
...or...
c:\cygwin\bin\bash -l -c /path/to/executable_script.sh
Note: the -l flag tell bash to "act as if it had been directly invoked by login" and use Bash Startup Files. This is important in that it sets your $PATH and other things you rely on when you launch a cygwin terminal. If you don't include -l or --login you will get "command not found" when you try to call anything except of a bash builtin.
The difference between the 2 is like the difference between doing...
bash script_to_interpret.sh
...and...
./executable_script.sh
...in *nix. The former interprets the script using bash. The latter executes the script (only if it has chmod +x executable_script.sh) and interprets it according to its "shebang" line. The latter method is also what you want to do if your executable is not a script at all, like a *nix binary compiled from source.)
It has been bugging me for a while I couldn't find the solution for this, but I finally got the right mix together.
You can simply do the following if you have cygwin on your PATH:
run bash test.js
If cygwin is not on your path, you can do this:
c:\cygwin\bin\run.exe -p /bin bash test.js
If you are looking for more control over the created window (maximize, etc) it looks like you can use cygstart also.
Sources:
- neves answer above (though that wasn't enough by itself for me personally to figure it out)
- http://cygwin.com/ml/cygwin/2008-09/msg00156.html
As the terminal can't close while your script is still running, try the command:
"nohup C:\foo.bsh; exit"
This way your script will be backgrounded and detached from the terminal, and it should exit quickly so the terminal goes away. I think that the window may still 'flash' with this approach, but the results should be better than what you're getting.
I'm running Cygwin64 and the xwin server link points to:
C:\cygwin64\bin\run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe
This creates an icon AND a notification on the taskbar. I don't like that. The icon is rather useless, the notification has all your menu options from .XWinrc.
So... I wrote a .vbs script to silently run this command and make the icon go away:
Set objShell = CreateObject("WScript.Shell")
objShell.Run("C:\cygwin64\bin\run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe"), 0
Another imperfect possibility is to run the script via a shortcut and set the shortcut's Run option to "minimized".
Go to the directory where you have installed cygwin(on my machine it is c:/cygwin64/bin)
Once there simply type "bash.exe"