System()

This is a discussion on System() within the C# Programming forums, part of the General Programming Boards category; G'Day everybody, Quick question. I am using MySQL for a database. I have textfiles that have to be converted and ...

  1. #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

  2. #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 Attached Files

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    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.

  4. #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

  5. #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

Popular pages Recent additions subscribe to a feed

Similar Threads

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

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