954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

comman line command

Hi all,
Can anyone suggest me commands which will take a given thing and execute it in the command line and return the output. system() doesnt suit me bcos
1.it returns int not entire output
2.it opens command line window(shell) ( I dont want to open the window or display the output in a window).
thanks for any help

kararu
Junior Poster in Training
50 posts since Sep 2006
Reputation Points: 20
Solved Threads: 0
 

If you are using Windows, try ShellExecute.

WolfPack
Postaholic
Moderator
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
 
Can anyone suggest me commands which will take a given thing and execute it in the command line and return the output. system() doesnt suit me bcos 1.it returns int not entire output 2.it opens command line window(shell) ( I dont want to open the window or display the output in a window).

You may want to search for popen . http://www.daniweb.com/techtalkforums/showthread.php?t=54481

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

Thanks wolpack,..... Iam using linux.
Thanks dave....I will search popen.

kararu
Junior Poster in Training
50 posts since Sep 2006
Reputation Points: 20
Solved Threads: 0
 

I found a solution.I redirected the output to a file handle.

kararu
Junior Poster in Training
50 posts since Sep 2006
Reputation Points: 20
Solved Threads: 0
 
#include <windows.h>
#include <iostream.h>

int main()
{
ShellExecute(NULL, "open", "regedit.exe", NULL, NULL, SW_SHOWNORMAL);
cout << "Example code.\n";

system("PAUSE");
}


ShellExecute is nice.

Quan Chi2
Junior Poster in Training
67 posts since Jul 2005
Reputation Points: 14
Solved Threads: 1
 

I'm using the following code compiling with cl.exe from VS .NET 2003:

// shell.c
#include <windows.h>
#include <iostream.h>

int main() 
{
  SHELLEXECUTE (NULL, "open", "Notepad.exe", NULL, NULL, SW_SHOWNORMAL);
  return 0;
}


But receive this error:
shell.obj : error LNK2001: unresolved external symbol, __imp__ShellExecuteA@24
shell.exe : fatal error LNK1120: 1 unresolved externals

I'm finding that it's easier to run ShellExecute from VB than it is in C. I must be missing something in the include statements?

Thanks for any help.

Regards,

Hank

hkdani
Posting Pro in Training
435 posts since Nov 2007
Reputation Points: 49
Solved Threads: 47
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You