![]() |
| | #1 |
| Registered User Join Date: Feb 2003
Posts: 184
| System() 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();
}
}
}
}
Thanks, Kendal |
| gvector1 is offline | |
| | #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 |
| gvector1 is offline | |
| | #3 |
| the hat of redundancy hat 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 | |
| | #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 | |
| | #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(); 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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |