Computer Webmaster Gaming Console Graphics Forum

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.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > Database
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

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.

Google
Closed Thread
 
LinkBack Thread Tools Display Modes
Old 07-01-2007, 9:35 PM   #1
Ted
 
Ted's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default running sql scripts from perl script

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

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Advertisements
Old 07-01-2007, 9:35 PM   #2
Peter H. Coffin
 
Peter H. Coffin's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default running sql scripts from perl script

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
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 9:35 PM   #3
Paul Lautman
 
Paul Lautman's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default running sql scripts from perl script

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.


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 9:35 PM   #4
Bill Karwin
 
Bill Karwin's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default running sql scripts from perl script

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.
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 9:35 PM   #5
Jerry Stuckle
 
Jerry Stuckle's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default running sql scripts from perl script

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
==================
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 9:35 PM   #6
Bill Karwin
 
Bill Karwin's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default running sql scripts from perl script

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.
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 9:35 PM   #7
Ted
 
Ted's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default running sql scripts from perl script

Thanks Bill, Peter, Paul and Jerry.

Your input is appreciated.

Bill, your example proved valuable, and worked like a charm.

Thanks again.

Ted

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Featured Websites
Free Space
Free Space
Free Space Free Space
Closed Thread
Tags: , , , ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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




All times are GMT +1. The time now is 12:24 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98