![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| I am not sure if this probleem is primarily perl or MySQL, so I'll try here first. With any luck, there is someone else here who uses perl to run sql scripts against a MySQL DB. First, the following is a command that I can run from the Windows console, and it works as expected. mysql -u my_uid --password=my_pword --database=my_db < C:\DesignDocs\load_data.sql Here are two versions of the relevant statement in my perl script that do not work: my @args = ("mysql","--user=my_uid","--password=my_pword","--database=my_db","<","C:\\DesignDocs\\load_data.sql "); print system(@args); my @args = ("mysql","--user=my_uid","--password=mypword","--database=my_db","<","C:\\DesignDocs\\load_data.sql "); print system(@args); Both of these give me, as output, the page describing proper usage of mysql, suggesting that mysql is not getting the parameters as I specified them. I expect I can work around this by creating a simple batch file, but that doesn't explain why my perl statements don't work when, as far as I can tell from the documentation I have at hand, they should have worked. Can anyone out there solve this puzzle? Thanks Ted | |||
| Advertisements |
| | #2 | ||
| On 22 May 2006 13:47:19 -0700, Ted wrote: > I am not sure if this probleem is primarily perl or MySQL, so I'll try > here first. With any luck, there is someone else here who uses perl to > run sql scripts against a MySQL DB. > > First, the following is a command that I can run from the Windows > console, and it works as expected. > > mysql -u my_uid --password=my_pword --database=my_db < > C:\DesignDocs\load_data.sql > > Here are two versions of the relevant statement in my perl script that > do not work: > > my @args = > ("mysql","--user=my_uid","--password=my_pword","--database=my_db","<","C:\\DesignDocs\\load_data.sql "); > print system(@args); > > > my @args = > ("mysql","--user=my_uid","--password=mypword","--database=my_db","<","C:\\DesignDocs\\load_data.sql "); > print system(@args); > > Both of these give me, as output, the page describing proper usage of > mysql, suggesting that mysql is not getting the parameters as I > specified them. > > I expect I can work around this by creating a simple batch file, but > that doesn't explain why my perl statements don't work when, as far as > I can tell from the documentation I have at hand, they should have > worked. > > Can anyone out there solve this puzzle? "<" is not an argument. It is a shell-dependant redirect of input from a file instead of a terminal keyboard. -- Either way, it'll remind the clued that there's only one letter difference between 'turkey' and 'turnkey'. -- Mike Andrews | |||
| | #3 | ||
| Peter H. Coffin wrote: > On 22 May 2006 13:47:19 -0700, Ted wrote: >> I am not sure if this probleem is primarily perl or MySQL, so I'll >> try here first. With any luck, there is someone else here who uses >> perl to run sql scripts against a MySQL DB. >> >> First, the following is a command that I can run from the Windows >> console, and it works as expected. >> >> mysql -u my_uid --password=my_pword --database=my_db < >> C:\DesignDocs\load_data.sql >> >> Here are two versions of the relevant statement in my perl script >> that do not work: >> >> my @args = >> ("mysql","--user=my_uid","--password=my_pword","--database=my_db","<","C:\\DesignDocs\\load_data.sql "); >> print system(@args); >> >> >> my @args = >> ("mysql","--user=my_uid","--password=mypword","--database=my_db","<","C:\\DesignDocs\\load_data.sql "); >> print system(@args); >> >> Both of these give me, as output, the page describing proper usage of >> mysql, suggesting that mysql is not getting the parameters as I >> specified them. >> >> I expect I can work around this by creating a simple batch file, but >> that doesn't explain why my perl statements don't work when, as far >> as I can tell from the documentation I have at hand, they should have >> worked. >> >> Can anyone out there solve this puzzle? > > "<" is not an argument. It is a shell-dependant redirect of input > from a file instead of a terminal keyboard. Yes, and he is trying to get the contents of the load_data.sql file to be redirected as input. | |||
| | #4 | ||
| Ted wrote: > mysql -u my_uid --password=my_pword --database=my_db < > C:\DesignDocs\load_data.sql This illustrates something you should understand about shell command processing if you're going to use the system() call from Perl. The shell don't pass all the args you see above to the child process. Specifically, redirects with ">" or "<" or "|" are handled by the shell, by remapping the file descriptors of the child process. Once the file descriptors are set up for the child process, then the remainder of the command line is passed to that child process as it exec's the named program. This is basically the way most UNIX shells work, with respect to I/O redirection. If you want to learn more about this, read POSIX C API docs on system calls like dup(), dup2(), execl(), fork(), etc. As far as I can tell, the modern "cmd.exe" on Windows works the same, though I believe the older DOS command shells actually pass the "<" redirection symbol to the child processes as arguments. But the mysql client assumes it's being run by the modern type of shell, and does not recognize "<" as an argument. The mysql client application provides a way to load a script without redirecting I/O. You can execute the literal client statement "SOURCE <file>" from the command line, using the mysql -e option. For example: my @args = ("mysql","--user=my_uid","--password=my_pword","--database=my_db","-e","source C:\\DesignDocs\\load_data.sql"); print system(@args); Regards, Bill K. | |||
| | #5 | ||
| Bill Karwin wrote: > Ted wrote: > >> mysql -u my_uid --password=my_pword --database=my_db < >> C:\DesignDocs\load_data.sql > > > This illustrates something you should understand about shell command > processing if you're going to use the system() call from Perl. > > The shell don't pass all the args you see above to the child process. > Specifically, redirects with ">" or "<" or "|" are handled by the shell, > by remapping the file descriptors of the child process. > > Once the file descriptors are set up for the child process, then the > remainder of the command line is passed to that child process as it > exec's the named program. This is basically the way most UNIX shells > work, with respect to I/O redirection. > > If you want to learn more about this, read POSIX C API docs on system > calls like dup(), dup2(), execl(), fork(), etc. > > As far as I can tell, the modern "cmd.exe" on Windows works the same, > though I believe the older DOS command shells actually pass the "<" > redirection symbol to the child processes as arguments. But the mysql > client assumes it's being run by the modern type of shell, and does not > recognize "<" as an argument. > > The mysql client application provides a way to load a script without > redirecting I/O. You can execute the literal client statement "SOURCE > <file>" from the command line, using the mysql -e option. > > For example: > > my @args = > ("mysql","--user=my_uid","--password=my_pword","--database=my_db","-e","source > C:\\DesignDocs\\load_data.sql"); > print system(@args); > > Regards, > Bill K. Bill, No, the old DOS shell interpreted redirection symbols itself ever since they were first implemented (DOS 2.0? 2.1? somewhere back then). -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== | |||
| | #6 | ||
| Jerry Stuckle wrote: > No, the old DOS shell interpreted redirection symbols itself ever since > they were first implemented (DOS 2.0? 2.1? somewhere back then). Interesting. I believe you that the I/O was handled by the DOS shell, but I could swear I've seen return messages from applications that made me think that the "<" arg was also passed to the app. I must have made an incorrect assumption. In any case, DOS is dead so it doesn't matter. ;-) Regards, Bill K. | |||
| | #7 | ||
| Thanks Bill, Peter, Paul and Jerry. Your input is appreciated. Bill, your example proved valuable, and worked like a charm. Thanks again. Ted | |||
| Featured Websites | ||||
|
![]() |
| Tags: perl, running, script, scripts, sql |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| calling perl script from mysql trigger | kees hessels | Database | 2 | 07-01-2007 7:37 PM |
| Need help with script conflict (Two scripts on one page) | P Wolpert | JavaScript | 0 | 07-01-2007 5:38 PM |
| A PHP script requires me to compile some scripts how do I dothis???? | Marius Mathiesen | PHP | 0 | 07-01-2007 3:59 PM |
| cgi scripts, GD libraries, perl, php, SSH, HELP | jim | PHP | 5 | 07-01-2007 3:31 PM |
| ScriptRunner script for CS2, neat way to launch scripts | Timo Autiokari | Graphics in general | 2 | 06-12-2007 12:26 AM |
| Featured Websites | ||||
|