how to open the filename( from comman line) in Window

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
linb
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Apr 26, 2012 9:38 am

how to open the filename( from comman line) in Window

Post by linb » Fri Apr 27, 2012 9:49 am

In DOS window, I type command line as follow:

> test.exe C:/test.txt2

And, press "enter". The string "C:/test.txt2" can be got, but the file can't be opened.

When I use "wxMessageBox(parser.getParam(0))", it shows "C:/test.txt2", but the file can't be opened. But when I open "C:/test.txt2" from test.exe UI, it works well.

why?

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2360
Joined: Sun Jan 03, 2010 5:45 pm

Re: how to open the filename( from comman line) in Window

Post by PB » Fri Apr 27, 2012 10:07 am

I believe you must be doing something wrong, assuming:
1. the file name is always the same absolute path;
2. you're opening the wxFile with the same mode from both command line and from UI;
3. the file exists and you have a permission to access it.

What is the exact message wxFile::Open() (or the constructor) gives you via wxLogError()? It should be something like e.g. "Error: can't open file 'c:/test.txt2' (error 2: System can not find the specified file.)". You should also post the code snippet you actually use for the opening file and maybe mention your wxWidgets platform.

asadilan
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Jul 27, 2010 10:42 pm

Re: how to open the filename( from comman line) in Window

Post by asadilan » Fri Apr 27, 2012 6:16 pm

sometimes its the / you may have to put double // or \\.
for easiest use wxfilename. that should be taken care of.
hopefully that helps.

linb
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Apr 26, 2012 9:38 am

Re: how to open the filename( from comman line) in Window

Post by linb » Sat Apr 28, 2012 1:17 am

bool MyApp::OnInit()
{
wxFrame *frame;
frame = new wxDocParentFrame(docManager, NULL, wxID_ANY,
GetAppDisplayName(),
wxDefaultPosition,
wxSize(800, 700));
....

m_templ = new wxDocTemplate(docManager, "oppo", "*.sop", "", "sop",
"OPPO Doc", "OPPO View",
CLASSINFO(DrawingDocument), CLASSINFO(DrawingView));

frame->SetIcon(wxICON(doc));
frame->Centre();
frame->Show(false);


// Those do not work, it alway to create a new empty document, "C:/a.txt" is expected to be opened.
// wxString filePath = _T("C:/a.txt");
// wxString filePath = _T("C://a.txt");


wxDocument * doc=m_templ->CreateDocument(filePath, true);


return true;
}

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2360
Joined: Sun Jan 03, 2010 5:45 pm

Re: how to open the filename( from comman line) in Window

Post by PB » Sat Apr 28, 2012 7:44 am

Just a wild guess here:
You register your document template with ".sop" file extension, yet you attempt to create the new document which has ".txt" extension. Maybe that's what confuses the template manager, as it doesn't know what document type to create for a file with ".txt" extension?

Anyway, this should be simple to figure out for you. Step into the CreateDocument() in the debugger and go through it to see where and why it fails. Also inspecting the debug log may also prove useful (i.e. the "Output" window in your IDE or whatever tool you use for catching wxLogDebug() calls).

By the way, you have to double "\" in string literals, not "/". So in your iDE you write either

Code: Select all

wxString path = wxT("c:/a.txt");
//or
wxString path = wxT("c:\\a.txt");
On MS Windows, the second way is more natural, because "\" is the native path separator there while "/" is used on command line as a an argument separator, as in e.g. " dir /B /oN ".

Post Reply