LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-19-2018, 04:01 PM   #1
superwavelet
LQ Newbie
 
Registered: May 2018
Posts: 4

Rep: Reputation: Disabled
Unhappy How to get the correct full file path from a remote linux machine correct


I use TigerVNC to access a remote linux machine. In my current path, if I type "pwd", then I got these lines shown in the ternial:

Code:
% pwd
/stateflow/devel
[myusername@sb33glnxa64: /stateflow/devel]
%
Right now, I want to write a program to run on the remote linux machine under /stateflow/devel/xx directory to save the file under this directory, but I tried to set the filePath to either

Code:
"\\\\sb33glnxa64\\stateflow\\devel\\MyLog.txt"
or
"\\stateflow\\devel\\MyLog.txt"
For example:

Code:
std::ofstream m_fStream;
std::string filePath("\\\\sb33glnxa64\\stateflow\\devel\\MyLog.txt");
m_fStream.open(filePath.c_str(), std::ofstream::out | std::ofstream::app);
m_fStream << "sMode is " << sMode << std::endl;
m_fStream.close();
But neither of them works, I cannot see the MyLog.txt file got created under the /stateflow/devel directory.

Not sure which path I should use here to set the filePath ? Thanks
By the way, I use C++

Note: the program to run is under a unknown temporary path /stateflow/devel/xx . So that's why I need to know the absolute path thus later I can find and open the MyLog.txt.

Last edited by superwavelet; 05-19-2018 at 05:25 PM.
 
Old 05-19-2018, 04:18 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,951

Rep: Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146
try taking a closer look at your slashes this / as apposed to this \

Quote:
Originally Posted by superwavelet View Post
I use TigerVNC to access a remote linux machine. In my current path, if I type "pwd", then I got these lines shown in the ternial:

Code:
% pwd
/stateflow/devel
[myusername@sb33glnxa64: /stateflow/devel]
%
Right now, I want to write a program to save the file under this directory, but I tried to set the filePath to either

Code:
"\\\\sb33glnxa64\\stateflow\\devel\\MyLog.txt"
or
"\\stateflow\\devel\\MyLog.txt"
For example:

Code:
std::ofstream m_fStream;
std::string filePath("\\\\sb33glnxa64\\stateflow\\devel\\MyLog.txt");
m_fStream.open(filePath.c_str(), std::ofstream::out | std::ofstream::app);
m_fStream << "sMode is " << sMode << std::endl;
m_fStream.close();
But neither of them works, I cannot see the MyLog.txt file got created under the /stateflow/devel directory.

Not sure which path I should use here to set the filePath ? Thanks
By the way, I use C++
 
Old 05-19-2018, 04:23 PM   #3
superwavelet
LQ Newbie
 
Registered: May 2018
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
try taking a closer look at your slashes this / as apposed to this \
Thank you very much!

I have tried:

Code:
"//sb33glnxa64/stateflow/devel/MyLog.txt"
or
"/stateflow/devel/MyLog.txt"
But still doesn't work.
 
Old 05-19-2018, 05:00 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,951

Rep: Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146
I am not familiar with remote access but I'd venture to say you're going to have to insure you have a connection, then take that and add it to the front of your path string then try to save it.

something I just whipped up. Creates a new file, adds to it then closes it in the path to indicated in hard code.
Code:
int main(int argc, char **argv)
{
    if (argc != 2)
    {
        cout<<"not enough args "<<argv<<endl;
        exit(EXIT_FAILURE);
    }
    std::string file = argv[1];
    std::string p = "/home/userx/Documents";
    p+="/";
    p += file;
    cout<<"P "<<p<<endl;
    fstream F;
    F.open( p, std::ifstream::out);
    if (F.is_open())
    {
        for (int i = 0; i < 10; i++)
        {
            F << i;
            F << endl;
        }

    }
    F.close();
    std::string line;
    F.open(p);
    if (F.is_open())
    {
        while ( getline(F, line) )
        {
            cout << line << endl;
        }
    }
    F.close();
   return 0;
}
results
Code:
$ pwd
/media/projects/C++Projects/screwingaround/bin/Debug

$ ./screwingaround mynewfile
P /home/userx/Documents/mynewfile
0
1
2
3
4
5
6
7
8
9

//file located here
$ ls ~/Documents
mynewfile
EDIT:

you're using a string then turning it into a char I do not know why
Code:
std::string filePath("\\\\sb33glnxa64\\stateflow\\devel\\MyLog.txt");
m_fStream.open(filePath.c_str(), std::ofstream::out | std::ofstream::app);
maybe fix your path assignment and remove the .c_str()
Code:
std::string filePath("\\\\sb33glnxa64\\stateflow\\devel\\MyLog.txt");
m_fStream.open(filePath, std::ofstream::out | std::ofstream::app);

Last edited by BW-userx; 05-19-2018 at 05:26 PM.
 
Old 05-19-2018, 05:27 PM   #5
superwavelet
LQ Newbie
 
Registered: May 2018
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
I am not familiar with remote access but I'd venture to say you're going to have to insure you have a connection, then take that and add it to the front of your path string then try to save it.

something I just whipped up. Creates a new file, adds to it then closes it in the path to indicated in hard code.
Code:
#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char **argv)
{
    if (argc != 2)
    {
        cout<<"not enough args "<<argv<<endl;
        exit(EXIT_FAILURE);
    }
    std::string file = argv[1];
    std::string p = "/home/userx/Documents";
    p+="/";
    p += file;
    cout<<"P "<<p<<endl;
    fstream F;
    F.open( p, std::ifstream::out);
    if (F.is_open())
    {
        for (int i = 0; i < 10; i++)
        {
            F << i;
            F << endl;
        }

    }
    F.close();

    cout<<argv[1];
   return 0;
}
results
Code:
$ pwd
/media/projects/C++Projects/screwingaround/bin/Debug

./screwingaround mynewfile
P /home/userx/Documents/mynewfile
mynewfile 

$ ls ~/Documents
mynewfile

$ cat  ~/Documents/mynewfile
0
1
2
3
4
5
6
7
8
9
EDIT:

you're using a string then turning it into a char I do not know why
Code:
std::string filePath("\\\\sb33glnxa64\\stateflow\\devel\\MyLog.txt");
m_fStream.open(filePath.c_str(), std::ofstream::out | std::ofstream::app);
maybe fix your path assignment and remove the .c_str()
Code:
std::string filePath("\\\\sb33glnxa64\\stateflow\\devel\\MyLog.txt");
m_fStream.open(filePath, std::ofstream::out | std::ofstream::app);
Thank you very much!
I have the access to the machine.
Sorry, I forget to mention: the program also run on the remote linux machine under an sub folder of /stateflow/devel . But the subfolder is created during the run and I do not know the name and the exact path of the sub folder. So that's why I need to know the absolute path thus later I can find and open the MyLog.txt.
 
Old 05-19-2018, 06:01 PM   #6
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,951

Rep: Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146
Quote:
Originally Posted by superwavelet View Post
Thank you very much!
I have the access to the machine.
Sorry, I forget to mention: the program also run on the remote linux machine under an sub folder of /stateflow/devel . But the subfolder is created during the run and I do not know the name and the exact path of the sub folder. So that's why I need to know the absolute path thus later I can find and open the MyLog.txt.
I updated my code but that I do not think is an issue, maybe take a peek at it.

So, your problem is whenever you log in you get assigned a new different sub directory under the parent dir /stateflow/devel which turns into /stateflow/devel/unknowName

this is Linux yes?

Code:
#include <iostream>
/*
#include <fstream>
#include <string>
*/
#include <boost/filesystem.hpp>

int main(int argc, char **argv)
{
    boost::filesystem::path p;
    p = boost::filesystem::current_path();
    std::cout << "Current path is : " << p << std::endl;
    //remove the quotes?? maybe??
    std::string WithoutQuotes;
    WithoutQuotes = boost::filesystem::canonical(p).string();
    WithoutQuotes.erase ( remove(WithoutQuotes.begin(), WithoutQuotes.end(), '\"') ,
    WithoutQuotes.end() );

    std::cout<<"Current path  n/Quotes "<<WithoutQuotes<<std::endl;

   return 0;
}
link -lboost_system -lboost_filesystem
Code:
$ ./screwingaround
Current path is : "/media/projects/C++Projects/screwingaround/bin/Debug"
Current path  n/Quotes /media/projects/C++Projects/screwingaround/bin/Debug

Last edited by BW-userx; 05-19-2018 at 06:09 PM.
 
Old 05-19-2018, 06:17 PM   #7
superwavelet
LQ Newbie
 
Registered: May 2018
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
I updated my code but that I do not think is an issue, maybe take a peek at it.

So, your problem is whenever you log in you get assigned a new different sub directory under the parent dir /stateflow/devel which turns into /stateflow/devel/unknowName

this is Linux yes?

Code:
#include <iostream>
/*
#include <fstream>
#include <string>
*/
#include <boost/filesystem.hpp>

int main(int argc, char **argv)
{
    boost::filesystem::path p;
    p = boost::filesystem::current_path();
    std::cout << "Current path is : " << p << std::endl;
    //remove the quotes?? maybe??
    std::string WithoutQuotes;
    WithoutQuotes = boost::filesystem::canonical(p).string();
    WithoutQuotes.erase ( remove(WithoutQuotes.begin(), WithoutQuotes.end(), '\"') ,
    WithoutQuotes.end() );

    std::cout<<"Current path  n/Quotes "<<WithoutQuotes<<std::endl;

   return 0;
}
link -lboost_system -lboost_filesystem
Code:
$ ./screwingaround
Current path is : "/media/projects/C++Projects/screwingaround/bin/Debug"
Current path  n/Quotes /media/projects/C++Projects/screwingaround/bin/Debug
Thank you. Yes, on linux. But the problem is the program will generate an .exe in a sub folder on that machine which I do not know and then run the .exe file from that subfolder. Moreover, when I ran the program, the std::cout will not print out the "current path" to the terminal. Thus, let me try our /home directory mentioned in the earlier reply.

Thanks!
 
Old 05-19-2018, 06:28 PM   #8
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,951

Rep: Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146
sounds like you're going to have to dig a little deeper in how to send receive communications between remote client -> to host terminals. feedback stuff. Which I'd even have to look into.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Am I heading down the correct path? tjyoung67 Linux - Newbie 4 04-04-2014 04:33 PM
motion the correct path g4ry Slackware 5 12-29-2012 12:54 PM
What is correct path to C compiler NeilJones Mandriva 6 04-29-2008 09:48 AM
jdk not in correct path angryfirelord Slackware 6 04-08-2007 10:14 AM
please tell me if my path statement is correct on RH 7.3 ergo_sum Linux - Newbie 9 12-12-2003 11:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration