From the command line I can do a dump and redirect it to a file without any issue.
sql=mysql_dump.sql
run_sql="mysqldump -u root -p scope_import > $sql"
$run_sql
When I run it from this script it gives an error: Not such table ‘>’ so its no seeing the > as a redirect rather a table name.
How about simply:
(I hope I haven’t misunderstood your question).