How to get the correct full file path from a remote linux machine correct
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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"
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.
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
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;
}
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.
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
$ ./screwingaround
Current path is : "/media/projects/C++Projects/screwingaround/bin/Debug"
Current path n/Quotes /media/projects/C++Projects/screwingaround/bin/Debug
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
$ ./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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.