Directory and System Problem

This is a discussion on Directory and System Problem within the C++ Programming forums, part of the General Programming Boards category; Hello All; This is a two part problem... First, i am trying to execute the call C:\Program Files\PostgreSQL.1\bin>pg_dump focus > ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    85

    Directory and System Problem

    Hello All;

    This is a two part problem...

    First, i am trying to execute the call
    C:\Program Files\PostgreSQL\8.1\bin>pg_dump focus > \\10.1.65.30\smbtest\backup.
    backup

    AND the seccond is...
    I need the password to be passed from the program

    Below is my code thus far, and if you haven't noticed, I am using postgreSQL

    Code:
    // test-app.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	//system("c:\progra~1\PostgreSQL\8.1\bin\pg_dump focus > \\10.1.65.30\smbtes\backup.backup");
    	 int i;
    	puts ("Trying to execute command PG_DUMP");
    	i = system ("pg_dump focus > \\10.1.65.30\smbtest\backup.backup");
    	if (i==-1) puts ("Error executing PG_DUMP");
    	else puts ("Command successfully executed");
    	system ("pause"); 
    	return 0;
    
    
    
    
    	return 0;
    }

    Windows Xp machine...and also note that the actual command fromt the command line does indeed work just not when the system does it..i think it has to do with the \'s

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    You really don't need two return 0s . . . .

    AND the seccond is...
    I need the password to be passed from the program
    Try this (disclaimer: it's not very secure at all), assuming that pg_dump takes the password for the standard input:
    Code:
    system("echo thisisthepassword | pg_dump focus > \\10.1.65.30\smbtest\backup.backup
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    85
    That is great.. it compiles now!! When executing though this is what I get;

    Trying to execute command PG_DUMP
    The filename, directory name, or volume label syntax is incorrect.
    Command successfully executed
    Press any key to continue . . .

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    85
    Update... it seems to be that the \'s are not working correctly, bc even if I specify a directory like c:\smbtest\... it still gives the same error and i am getting a successful compile, with this message:

    c:\documents and settings\stan swank ii\my documents\visual studio 2005\projects\test-app\test-app\test-app.cpp(11) : warning C4129: 's' : unrecognized character escape sequence

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    * slaps head *

    Change
    Code:
    system ("pg_dump focus > \\10.1.65.30\smbtest\backup.backup");
    to
    Code:
    system ("pg_dump focus > \\\\10.1.65.30\\smbtest\\backup.backup");
    [edit] Because \ has special meaning (treat the following character as something special), to include a \ in a string, you have to use \\. To include two \s in a row, use \\\\ and so on. [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    85
    Awesome Thx... Now do you know how to return the system date... I would like to use it as the filename.backup

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Try time() and localtime() in <ctime>.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to programe directory system in C.
    By danish&ali in forum C Programming
    Replies: 4
    Last Post: 12-04-2008, 08:47 AM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. Problem With Code In Ubuntu ,please Help Me
    By krisvamc in forum C Programming
    Replies: 2
    Last Post: 04-12-2007, 11:55 PM

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