Hello all;
I am running windows...developing a windows command program.
I am having some problems with my command line arguments though.
Here is my code:
Code:// test-app.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <ctime> #include "string.h" #include <iostream> #include <string> using namespace std; int _tmain(int argc, char* argv[]) { int j; //system("c:\progra~1\PostgreSQL\8.1\bin\pg_dump focus > \\10.1.65.30\smbtes\backup.backup"); string filename; char dateStr[9]; string toDo; //_strdate(dateStr); _strdate_s(dateStr); for (j = 0; j < argc; j++) { cout << "Argc: " << j << " = " << argv[j] << endl; } filename = "Backup-"; filename = filename + dateStr; filename = filename + ".backup"; toDo = "pg_dump -h localhost -U swanley007 focus > \\\\10.1.2.16\\smbtest\\"; toDo = toDo + filename; //cout << filename << endl; //cout << toDo << endl; int i; puts ("Trying to execute command PG_DUMP"); i= system (toDo.c_str()); //i= system ("pg_dump -h localhost -U swanley007 focus > \\\\10.1.65.30\\smbtest\\backup.backup"); //i = system ("pg_dump focus > \\10.1.65.30\smbtest\backup.backup"); system ("pause"); return 0; }
here is my run and output:
C:\Program Files\PostgreSQL\8.1\bin>test-app -h
Argc: 0 = t
Argc: 1 = -
Trying to execute command PG_DUMP
Access is denied.
Press any key to continue . . .
C:\Program Files\PostgreSQL\8.1\bin>test-app -h 192.168.1.1
Argc: 0 = t
Argc: 1 = -
Argc: 2 = 1
Trying to execute command PG_DUMP
Access is denied.
Press any key to continue . . .
C:\Program Files\PostgreSQL\8.1\bin>
I am wondering why it is only getting the first character in each argument. I think is has to do with the char*, but this works in linux fine..... Help would be great