Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 26th, 2006, 10:49 AM   #1
Lich
Professional Programmer
 
Lich's Avatar
 
Join Date: May 2005
Location: Detroit
Posts: 254
Rep Power: 4 Lich is on a distinguished road
Send a message via AIM to Lich Send a message via MSN to Lich
Spaces in system() function

So it's time I ventured into C++. In my attempt to make a quick and useful program, i'm coming across a problem. How can I use spaced in the system() function to call a program living in the program files folder?
__________________
--John Cruz
Web Developer
www.cruzweb.net
Lich is offline   Reply With Quote
Old Apr 26th, 2006, 12:39 PM   #2
Jason Isom
Programmer
 
Join Date: Dec 2005
Posts: 53
Rep Power: 3 Jason Isom is on a distinguished road
Quote:
Originally Posted by Lich
So it's time I ventured into C++. In my attempt to make a quick and useful program, i'm coming across a problem. How can I use spaced in the system() function to call a program living in the program files folder?
Did you try using
system("\"c:\\Program Files\\YourApp.exe\"");

You have to add quotations around it so that it won't parse it as a command followed by an argument list.
Jason Isom is offline   Reply With Quote
Old Apr 26th, 2006, 12:53 PM   #3
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
I think
system("C:\\Program files\\myexe.exe");
or
system("C:/Program files/myexe.exe");
should work.

Edit: shouldn't leave the tab open for a long time.
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Apr 26th, 2006, 3:43 PM   #4
Lich
Professional Programmer
 
Lich's Avatar
 
Join Date: May 2005
Location: Detroit
Posts: 254
Rep Power: 4 Lich is on a distinguished road
Send a message via AIM to Lich Send a message via MSN to Lich
hmm...none of it is working. here's my code, everything commented out i've tried and doesn't work.It's basically supposed to unmount an alcohol120% virtual drive.

#include <iostream>

using namespace std;

int main()
{
   // system("C:\program\ files\alcohol soft\alcohol 120\AxCmd.exe E: /u");
   // system("\"C:\program\ files\alcohol soft\alcohol 120\AxCmd.exe E: /u\"");
    system("C:\\Program\ files\\alcohol\ soft\\alcohol\ 120\\AxCmd.exe\ E:\ /u");
    system("PAUSE");
    return EXIT_SUCCESS;
}

they all give me the error:
'C:\Program' is not recognized as an internal or external command, operable program or batch file.
Press any key to continue . . .
__________________
--John Cruz
Web Developer
www.cruzweb.net
Lich is offline   Reply With Quote
Old Apr 26th, 2006, 3:49 PM   #5
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by Lich
hmm...none of it is working.
How about:

#include <iostream>

using namespace std;

int main()
{
    system("C:\\program files\\alcohol soft\\alcohol 120\\AxCmd.exe E: /u");
    system("PAUSE");
    return EXIT_SUCCESS;
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Apr 26th, 2006, 3:53 PM   #6
Lich
Professional Programmer
 
Lich's Avatar
 
Join Date: May 2005
Location: Detroit
Posts: 254
Rep Power: 4 Lich is on a distinguished road
Send a message via AIM to Lich Send a message via MSN to Lich
nope, same thing. Is just converting it to the short path name the best way to go? Like at http://www.tek-tips.com/viewthread.c...1218192&page=1
__________________
--John Cruz
Web Developer
www.cruzweb.net
Lich is offline   Reply With Quote
Old Apr 26th, 2006, 3:56 PM   #7
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
you can try the 6 char trick:
system("C:\\Progra~1\\alcoho~1\\alcoho~1\\'AxCmd.exe E: /u'");
OpenLoop is offline   Reply With Quote
Old Apr 26th, 2006, 4:03 PM   #8
Lich
Professional Programmer
 
Lich's Avatar
 
Join Date: May 2005
Location: Detroit
Posts: 254
Rep Power: 4 Lich is on a distinguished road
Send a message via AIM to Lich Send a message via MSN to Lich
Quote:
Originally Posted by OpenLoop
you can try the 6 char trick:
system("C:\\Progra~1\\alcoho~1\\alcoho~1\\'AxCmd.exe E: /u'");
you're a beast! the 's around the command didn't work but
system("C:\\Progra~1\\alcoho~1\\alcoho~1\\AxCmd.exe E: /u");
sure did. much thanks.
__________________
--John Cruz
Web Developer
www.cruzweb.net
Lich is offline   Reply With Quote
Old Apr 26th, 2006, 4:07 PM   #9
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by OpenLoop
you can try the 6 char trick:
system("C:\\Progra~1\\alcoho~1\\alcoho~1\\'AxCmd.exe E: /u'");
Dang DOS 8.3 format. I should disable it.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Apr 26th, 2006, 4:09 PM   #10
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Quote:
Originally Posted by nnxion
Dang DOS 8.3 format. I should disable it.
I'll kill ya . I still use Dos every now and then just for good childhood memories.
OpenLoop is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:50 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC