Saltar para o conteúdo principal
Versão: Próximo

Interface de linha de comando

You can use the macOS Terminal or the Windows console to drive your 4D applications (4D, 4D Server, merged application, and tool4d) using command lines. Mais especificamente, essa funcionalidade permite que:

  • lance um banco de dados remotamente, que pode ser útil especialmente para administrar servidores Web.
  • roda automaticamente testes para suas aplicações.

Informação básica

Pode executar linhas de comando para aplicações 4D usando o terminal macOS ou o console Windows.

  • Under macOS, you should use the open command.
  • Em Windows pode passar os argumentos diretamente.

Em macOS pode passar os argumentos diretamente indo à pasta onde está a aplicação dentro do pacote (rota Contents/MacOS) que permite dirigir o stream stderr. For example, if the 4D package is located in the MyFolder folder, you must write the command line as follows: /MyFolder/4D.app/Contents/MacOS/4D. However, we recommend that you use the open command whenever you do not need to access the stderr stream.

Lançar uma aplicação 4D

Aqui está uma descrição das linhas de comando e os argumentos compatíveis com o lançamento de aplicações 4D.

Sintaxe:

<applicationPath> [--version] [--help] [--project] [<projectPath | packagePath | 4dlinkPath> [--data <dataPath>]] 
[--opening-mode interpreted | compiled] [--create-data] [--user-param <user string>] [--headless] [--dataless]
[--webadmin-settings-file] [--webadmin-access-key] [--webadmin-auto-start] [--webadmin-store-settings]
[--utility] [--skip-onstartup] [--startup-method <methodName string>]
Argumento&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ValorDescrição
applicationPathRota de 4D, Servidor 4D ou da aplicação fusionada.Lança a aplicação. Mesmo que dar um clique duplo na aplicação. Quando chamado sem um argumento de arquivo estrutura, a aplicação é executada e a caixa de diálogo "selecionar banco de dados" aparece.
--versionExibe a versão da aplicação e termina
--helpExibe ajuda e sai. Outros argumentos: -?, -h
--projectprojectPath | packagePath | 4dlinkPathArquivo de projeto para abrir com o arquivo de dados atual. Não aparece nenhuma caixa de diálogo.
--datadataPathArquivo de dados a abrir com o arquivo de projeto designado. Se não for especificado, 4D usa o último arquivo aberto.
--opening-modeinterpreted | compiledPede para o banco de dados abrir em modo interpretado ou compilado. Nenhum erro é gerado se o modo pedido estiver indisponível.
--create-dataCria automaticamente um novo arquivo de dados se nenhum arquivo válido for encontrado. Não aparece nenhuma caixa de diálogo. 4D usa o nome de arquivo passado no argumento "--data" se houver (gera um erro se um arquivo com o mesmo nome já existir).
--user-paramString usuário personalizadaA string that will be available within the application through the Get database parameter command (the string must not start with a "-" character, which is reserved).
--headlessLança 4D, Servidor 4D, ou a aplicação fusionada, sem uma interface (modo headless). In this mode:
  • The Design mode is not available, database starts in Application mode
  • No toolbar, menu bar, MDI window or splash screen is displayed
  • No icon is displayed in the dock or task bar
  • The opened database is not registered in the "Recent databases" menu
  • The diagnostic log is automatically started (see SET DATABASE PARAMETER, selector 79)
  • Every call to a dialog box is intercepted and an automatic response it provided (e.g. OK for the ALERT command, Abort for an error dialog...). All intercepted commands(*) are logged in the diagnostic log.

  • For maintenance needs, you can send any text to standard output streams using the LOG EVENT command. Note that headless 4D applications can only be closed by a call to QUIT 4D or using the OS task manager.
    --datalessO modo sem dados é útil quando 4D rodar tarefas que não precisam de dados (por exemplo na compilação de projetos). Lança 4D, servidor 4D ou uma aplicação fusionada em modo Dataless. In this mode:
  • No file containing data is opened, even if specified in the command line or the .4DLink file, or when using the CREATE DATA FILE and OPEN DATA FILE commands.
  • Commands that manipulate data will throw an error. For example, CREATE RECORD throws “no table to apply the command to”.

  • Note:
  • If passed in the command line, dataless mode applies to all databases opened in 4D, as long as the application is not closed.
  • If passed using the .4DLink file, dataless mode only applies to the database specified in the .4DLink file. For more information on .4DLink files, see Project opening shortcuts.
  • --webadmin-settings-fileRota do arquivoPath of the custom WebAdmin .4DSettings file for the WebAdmin web server. Not available with tool4d.
    --webadmin-access-keyStringAccess key for the WebAdmin web server. Not available with tool4d.
    --webadmin-auto-startParâmetrosStatus of the automatic startup for the WebAdmin web server. Not available with tool4d.
    --webadmin-store-settingsStore the access key and automatic starting parameters in the currently used settings file (i.e. the default WebAdmin.4DSettings file or a custom file designated with the --webadmin-settings-path parameter). Use the --webadmin-store-settings argument to save these settings if necessary. Not available with tool4d.
    --utilityApenas disponível com 4D Server. Launches 4D Server in utility mode.
    --skip-onstartupLaunches the project without executing any "automatic" methods, including the On Startup and On Exit database methods
    --startup-methodNome do método projecto (string)Project method to execute immediately after the On Startup database method (if not skipped with --skip-onstartup).

    (*) Some dialogs are displayed before the database is opened, so that it's impossible to write into the Diagnostic log file (licence alert, conversion dialog, database selection, data file selection). Nesses casos, uma mensagem de erro é criada tanto no stream stderr e no arquivo de eventos do sistema, e então a aplicação fecha.

    Exemplos

    A pasta atual do usuário é alcançada usando o comando "~ " em macOS e o comando "%HOMEPATH%" em Windows.

    Lance uma aplicação 4D armazenada no desktop:

    • macOS:
    open ~/Desktop/4D.app
    open "~/Desktop/4D Server.app"
    • Windows:
    %HOMEPATH%\Desktop\4D\4D.exe
    %HOMEPATH%\Desktop\"4D Server.exe"

    Abrir um ficheiro de pacote em macOS:

    --args ~/Documents/myDB.4dbase

    Abrir um ficheiro de projecto:

    • macOS:
    --args ~/Documentos/myProj/Projecto/myProj.4DProject
    • Windows:
    %HOMEPATH%\Documents\myProj\Project\myProj.4DProject

    Abrir um ficheiro de projecto e um ficheiro de dados:

    • macOS:
    --args --project ~/Documents/myProj/Project/myProj.4DProject --data ~/Documents/data/myData.4DD
    • Windows:
    --project %HOMEPATH%\Documents\myProj\Project\myProj.4DProject --data %HOMEPATH%\Documents\data\myData.4DD
    ou:
    /project %HOMEPATH%\Documents\myProj\Project\myProj.4DProject /data %HOMEPATH%\Documents\data\myData.4DD

    Abrir um ficheiro .4DLink:

    • macOS:
    ~/Desktop/MyDatabase.4DLink
    • Windows:
    %HOMEPATH%\Desktop\MyDatabase.4DLink

    Abrir em modo compilado e criar um arquivo de dados se não disponível:

    • macOS:
    ~/Documents/myBase.4dbase --args --opening-mode compiled --create-data true
    • Windows:
    %HOMEPATH%\Documents\myBase.4dbase\myDB.4db --opening-mode compiled --create-data true

    Abrir um ficheiro projeto e um arquivo de dados e passar uma “string” como parâmetro do usuário:

    • macOS:
    --args --project ~/Documents/myProj/Project/myProj.4DProject --data ~/Documents/data/myData.4DD --user-param "Hello world"
    • Windows:
    --project %HOMEPATH%\Documents\myProj\Project\myProj.4DProject --data %HOMEPATH%\Documents\data\myData.4DD --user-param "Hello world"

    Aberto sem interface (modo headless):

    • macOS:
    --args --project ~/Documents/myProj/Project/myProj.4DProject --data ~/Documents/data/myData.4DD --headless  
    • Windows:
    --project %HOMEPATH%\Documents\myProj\Project\myProj.4DProject --data %HOMEPATH%\Documents\data\myData.4DD --headless

    tool4d

    tool4d is a free, lightweight, stand-alone application allowing you to open a 4D project in headless mode and execute some 4D code using the CLI.

    tool4d está disponível em Windows e macOS e está sempre associado a uma versão 4D (mesma versão e número de compilação). Só é fornecido na localização em inglês.

    tool4d é uma ferramenta perfeita para o fazer:

    • implementar uma cadeia CI/CD para sua aplicação 4D,
    • usar um executável 4D leve para executar scripts 4D, por exemplo, para executar testes unitários automáticos.

    Utilizar tool4d

    You can get tool4d from the 4D Product download page.

    You use tool4d by executing a command line with a standard 4D project. You can use all arguments described in the above table, except --webadmin since this component is disabled in tool4d. Com tool4d, é lançada a seguinte sequência específica:

    1. tool4d executes the On Startup database method (and all "automatic" methods such as user method), except if the --skip-onstartup argument is passed.
    2. tool4d executes the method designated by the --startup-method argument, if any.
    3. tool4d executes the On Exit database method, except if the --skip-onstartup argument is passed.
    4. tool4d desiste.

    On Windows, tool4d is a console application so that the stdout stream is displayed in the terminal (cmd, powershell...).

    Notas
    • tool4d is always executed headless (the headless command line option is useless).
    • The Application type command returns the value 6 ("tool4d") when called from the tool4d application.
    • the diagnostic log file is prefixed with "4DDiagnosticLogTool".

    Funcionalidades 4D desativadas

    Keep in mind that tool4d runs automatically in headless mode (see --headless in this table), and does neither give access to the 4D IDE nor any of its servers. Em particular, são desactivadas as seguintes funcionalidades:

    • servidor de aplicações, servidor Web, servidor SQL,
    • programador de cópias de segurança,
    • ODBC e SQL pass-through,
    • todos os componentes tais como 4D View Pro, 4D SVG, 4D NetKit...,
    • corrector ortográfico hunspell,
    • japanese spellchecker (mecab library),
    • WebAdmin,
    • CEF,
    • PHP,
    • remote debugger (local debugger, TRACE command and breakpoints are ignored in headless applications).

    4D Server em modo utilitário

    You can launch a 4D Server instance in a utility mode (headless) by using the --utility CLI option. Neste caso, é accionado o seguinte fluxo de trabalho:

    1. 4D Server executes the On Startup database method (and all "automatic" methods such as user method), except if the --skip-onstartup parameter is passed.
    2. 4D Server executes the method designated by the --startup-method, if any.
    3. 4D Server executes the On Exit database method, except if the --skip-onstartup parameter is passed.
    4. 4D Server é encerrado.
    info

    Ao contrário de tool4d, 4D Server em modo utilitário tem todas as suas funcionalidades ativadas. No entanto, o servidor de aplicações e todos os outros servidores não são iniciados.

    Veja também

    See this blog post for examples of how to use tool4d and 4D Server in utility mode.