Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am coding a little software for my personal use.
I want to open a text file with notepad by passing the file path to it.
I know how to do that in C#. it is as the following:

using System.Diagnostics; ///this is necessary to start the process
C#
Process.Start(@"C:\Windows\System32\notepad.exe","C:\myDatabase\namesList.snk");


I would like to do the same in C-Language.

I really appreciate your help.

thanks in advance

What I have tried:

I tried to use the shellExecute function, but there was no parameter for the path of the file to be opened by the executed program.

that is to say; I want to pass the file path to the program (notepad) and launch it so that it opens the specified file.
Posted
Updated 2-Mar-16 1:46am
v2

Did you try this

C++
#include <stdlib.h>  

int main () {
    system ("notepad C:\myDatabase\namesList.txt");
    return 0;
}</stdlib.h>



You can omit "Notepad" too if the text file default program is associated to notepad
 
Share this answer
 
Comments
Eng Tahlil 2-Mar-16 7:29am    
thanks gentleman; but the file I want the NOTEPAD to open is not associated to notepad. it is associated to no program in my PC.

what do I have to do, then?
Better Option would be this
C++
ShellExecute( NULL, "open", 
    "C:\\myDatabase\\namesList.txt",        
    NULL,       
    NULL,       
    SW_SHOWNORMAL 
);
 
Share this answer
 
Comments
Eng Tahlil 2-Mar-16 7:30am    
what do I have to do if notepad is not associated with the file
I used to do this so many years ago - but it was in a DOS system. Checking to see if all is still the same, I refer you to winapi - how can I run an external program In C? - Stack Overflow[^]

There also used to be a family of spawn and exec commands. As I recall, they were what I used: Help - QNX SDP 6.6 Documentation[^]
 
Share this answer
 
Comments
Eng Tahlil 2-Mar-16 7:32am    
thanks W∴ Balboos. it only shows how to run an app; but I want to pass the app a file path so that it opens after it is launched.

thanks.
W Balboos, GHB 2-Mar-16 7:37am    
Did you consider the spawnl() group ? It allows for arguments
Eng Tahlil 2-Mar-16 8:08am    
I will try
Use ShellExecuteEx[^] and pass the parameters in the ShellExecuteInfo[^] structure.

Article on the subject - A newbie's elementary guide to spawning processes[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900