본문 바로가기

프로그래밍/기타41

[Linux, C++] 파일 존재, 읽기, 쓰기, 실행 권한 여부 확인하는 방법 (access) access()를 이용하여 해당하는 파일이 있나, 읽기, 쓰기 실행을 할 수 있는지 알 수 있어요. ○ 헤더 및 함수 #include // *pathname : 파일 경로 // mode : 파일에 대한 확인 모드 (F_OK, R_OK, W_OK, X_OK) int access(const char *pathname, int mode); ○ 리턴값 0 : 성공 (파일 있음, 접근 가능) -1 : 실패 (파일 없음, 접근 권한 없음) ○ 예제 #include const char* file = "/home/ubuntu/test.mp4"; if (access(file, F_OK) == 0) { } if (access(file, R_OK) == 0) { } 2021. 5. 15.
[Linux, C++] 파일 소유자, 파일 크기, 접근/수정 시간 등 파일 정보 보는 방법 ○ 헤더 및 함수 #include #include #include int stat(const char *pathname, struct stat *statbuf); int fstat(int fd, struct stat *statbuf); int lstat(const char *pathname, struct stat *statbuf); - 리턴 값 0 : 성공 -1 : 에러 On success, zero is returned. On error, -1 is returned, and errno is set appropriately. ○ stat 구조체 설명 struct stat { dev_t st_dev; /* ID of device containing file */ ino_t st_ino; /* Inode n.. 2021. 5. 15.
[Linux, Qt] QProcess로 쉘 명령어, 프로그램 시작하는 방법 Qt에서 QProcess를 이용하여 프로그램이나, 명령어를 실행할 수 있으며 Arguments 값도 넣어 실행가능하고 터미널에서 명령어를 실행하여 나오는 결과 값도 받아 낼 수 있어요. - 사용 방법 #include int QProcess::execute(const QString &program, const QStringList &arguments) void QProcess::start(const QString &program, const QStringList &arguments, QIODevice::OpenMode mode = ReadWrite) ○ 명령어, 프로그램 실행이 종료될 때까지 대기하기 bool QProcess::waitForFinished(int msecs = 30000) - 설명 1. 사.. 2021. 5. 14.
[Linux, Ubuntu] SCP를 이용하여 원격지로 네트워크로 파일 전송, 다운로드 하기 ○ SCP를 이용하여 파일 전송하기 - 보낼 대상에 사용자 계정의 암호가 있을 경우 계정의 암호를 물어보고 인증에 성공해야 파일을 정상적으로 전송합니다. - 처음 접속하는 대상이라면 신뢰하는 목록에 등록하겠냐고 물어보기도 합니다. scp [보낼 파일] [보낼 대상의 사용자 계정의 ID]@[보낼 대상의 IP]:[전송 받을 위치] 예) 전송 진행율, 속도, 시간 등을 보여줌 $ scp test.mp4 root@192.168.1.10:/usr/. test.mp4 100% 60MB 6.6MB/s 00:09 예) 접속이 끊긴 경우 (네트워크 단절) $ scp test.mp4 root@192.168.1.10:/usr/. ssh: connect to host 192.168.1.10 port 22: No route t.. 2021. 5. 10.