Results 1 to 3 of 3

Thread: How to execute shell command which uses a pipe

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2016
    Posts
    204

    How to execute shell command which uses a pipe

    Hey

    I'm trying to pipe output from mysqldump to mysql using a pipe. It works just fine in a dos prompt, but fails when I use it in ShellExecute.
    The simplified command is:
    Code:
        r = ShellExecute(0, "open", "mysqldump.exe", _
            "mysqldump --user=foo --password=foo --host=192.168.1.2 --compress --verbose some_db | mysql --user=bar --password=bar --host=localhost some_db", _
            mariadbPath & "\bin", 1)
    The cmd window pops up for a split second then closes, too fast to see what it says - anyone know how to prevent it from closing?

    If I run that in a loop, I can step through the loop (F8) and the cmd window re-opens so often that I can make out what it says - authentication failure. It's not treating the pipe character as a pipe, it's not treating the stuff after the pipe symbol as a separate "mysql" command, but as arguments to the first "mysqldump" command.

    Same problem if instead I try "foo > somefile.txt", the chevron is not treated as redirection.

    How do I feed data from one command to another via a pipe? Must work in WinXP and Win10.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,151

    Re: How to execute shell command which uses a pipe

    There is no DOS, thus no "DOS prompt" but I assume you are talking about a run of cmd.exe instead.

    The command-line "piping" you are trying to use is performed by cmd.exe which your code doesn't run. What you'll have to do is run cmd.exe with the /c switch, passing the desired command-line string as an argument.

    ShellExecute() is buying you nothing here. You may as well use the intrinsic Shell() function.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2016
    Posts
    204

    Re: How to execute shell command which uses a pipe

    Err yeah, I meant "command prompt".

    Thank you, Shell() worked well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width