C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-07-2003, 08:36 AM   #1
Registered User
 
Join Date: Feb 2003
Posts: 184
System()

G'Day everybody,

Quick question. I am using MySQL for a database. I have textfiles that have to be converted and then loaded into MySQL. I have written a program to do the conversion. I am having a problem with getting the program to load the result textfile into MySQL. I have been trying to use mysqlimport, but I cannot get it to work. It works on a direct command line, but not in the program. Here is a bit of code:

Code:
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;

namespace CSCommandLine
{
	class Command
	{
		[STAThread]
		static void Main(string[] args)
		{
			Process myProcess = new Process();

			try
			{	
				string filename = "F:\\Test Folder\\MYSQL Update\\patientfile.txt";
				//myProcess.StartInfo.FileName = "mysqlimport.exe";
				//myProcess.StartInfo.Arguments = "jmapatients" + filename;
				//myProcess.StartInfo.CreateNoWindow = true;
				//myProcess.Start();
				//myProcess.WaitForExit();
				Process.Start("mysqlimport.exe", "jmapatients " + filename);
				Console.ReadLine();
			}

			catch(Exception ex)
			{	
				Console.WriteLine("" + ex);
				Console.ReadLine();
			}
		}
	}
}
I have tried a bunch of different approaches and nothing works. With this code, it runs, but does not update the database. A window with some text in it pops up for a split second and closes, but nothing happens to the database. Are there any suggestions?????????

Thanks,
Kendal
gvector1 is offline   Reply With Quote
Old 08-07-2003, 03:53 PM   #2
Registered User
 
Join Date: Feb 2003
Posts: 184
Think it is a bug in .NET

!!Update!! I have modified the code a little bit.
I have run across something in C# using the Process class and a configuration file.
When trying to set the argurments for the process through ProcessInfo.Arguements = (configuration file parameter), I run across a problem. Even though the file path is correct in the configuration file and if used to open a Streamwriter in another program. The configuration file parameter is a long pathname with spaces. When it hits the space, it stops. I have included the project for anyone who would like to better understand the problem. If anyone figures out something, please let me know.

Thanks,
Kendal
Attached Files
File Type: zip cscommandline.zip (13.2 KB, 41 views)
gvector1 is offline   Reply With Quote
Old 08-08-2003, 12:36 AM   #3
the hat of redundancy hat
 
nvoigt's Avatar
 
Join Date: Aug 2001
Location: Hannover, Germany
Posts: 2,769
I haven't looked at your code, but filenames with spaces will fail from the commandline as well.

mysqlimport.exe jmapatients afile name.txt

will fail because the parameters are
jmapatients
afile
name.txt

mysqlimport.exe jmapatients "afile name.txt"

will run because the parameters are
jmapatients
"afile name.txt"

Try to quote your filename.
__________________
hth
-nv

She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

When in doubt, read the FAQ.
Then ask a smart question.
nvoigt is offline   Reply With Quote
Old 08-08-2003, 07:09 AM   #4
Registered User
 
Join Date: Feb 2003
Posts: 184
In the parameter file, it is in quotes. I even tried storing the file path in a string and then using the string as one of the arguements and it still comes across the problem. I need to use the filename from the configuration file. I can use the configuration parameter as a Streamwriter or Stream reader and it the program accepts it and writes to it just fine. If I try to use it with the Process class, I get the errors. The only way it will work now is if I use the short filename path in the config file. Any suggestions?

Thanks,
Kendal
gvector1 is offline   Reply With Quote
Old 08-08-2003, 01:31 PM   #5
Registered User
 
Join Date: Feb 2003
Posts: 184
I have solved the problem by using double quotes as follows:

arguments = "mysqlimport jmapatients " + "\"" +
parameter + "\"";

That will work. Now I am having a problem with mysqldump.
I put in the following code:

Code:
Process dir = new Process(); 

				dir.StartInfo.FileName = "mysqldump"; 
				dir.StartInfo.UseShellExecute = false; 
				dir.StartInfo.CreateNoWindow = true;


				
				dir.StartInfo.Arguments = "jmapatients patientfile > F:\\dump.txt";
				dir.StartInfo.RedirectStandardInput = true; 
				dir.StartInfo.RedirectStandardError = true; 
				dir.StartInfo.RedirectStandardOutput = true; 

				dir.Start();
When it executes, it dumps the patientfile table out to display instead of the dump.txt file. Once done dumping, I get an error line at the end saying this:

mysqldump: Can't get CREATE TABLE for table '>' (Can't find file: '.\jmapatients\>.frm' (errno: 22))

What do you think? Apparently it is having a problem with the '>' character. Any suggestion??????????

Thanks,
Kendal
gvector1 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
File System Implementation dodgeviper C Programming 9 11-16-2007 01:04 PM
Using system icons @nthony Windows Programming 1 01-13-2007 07:56 PM
Linux database system needed BobS0327 Tech Board 7 06-11-2006 03:56 PM
BIOS system and memory allocation problem beely Tech Board 9 11-25-2003 07:12 AM
Number system base M, print numbers N digits wide... biterman C Programming 12 11-19-2001 04:31 AM


All times are GMT -6. The time now is 06:06 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22