Search code examples
batch-filecmdcommand-linecommandpsexec

Run command inside a process started using CMD


I want to write a batch file to run specific process, and run a command inside the process itself which runs inside the command prompt, then show results on console.

normally, I would open the CMD, type the process name/path: ggsci.exe, once it is running I run commands inside it (it actually connects to Oracle DB), for example :

enter image description here

How do I create a batch file does the same, this runs the process itself:

@ECHO OFF
ECHO running:
cd /d d:\
ggsci.exe

How to give ggsci.exe another command ?

Another option would be running the same using PsExec.exe.


Solution

  • According to the Oracle Golden Gate manual :

    To Input a Script

    Use the following syntax from the command line of the operating system.

    ggsci < input_file
    

    Update

    Probably this will work the same way:

    echo SELECT * from my.table|ggsci

    You can even use variables for dynamic scripts , though you you'll have to deal with the escaping the special symbols.

    Other option is to generate a temp file and then use it:

    echo SELECT * from my.table >temp_file
    ggsci < temp_file
    del /q /f temp_file
    

    you can even use template files and replace the content