⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fork.c.c

📁 OCCI STL 在 UNIX 下的应用 fock 应用实例
💻 C
字号:
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <iostream>
#include <fstream>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string>
#include <vector>
#include <dirent.h>
using namespace std;

int FileNextPathControl(string FirstPath,string NextPath,string Appendix)
{
	cout<<"FirstPath in FileNextPathControl = "<< FirstPath<<endl;
	cout<<"NextPath in FileNextPathControl = "<<NextPath <<endl;
	cout<<"Appendix in FileNextPathControl = "<< Appendix<<endl;
	cout<<"current Path will be :"<<NextPath<<endl;
  struct stat statbuf;
  if((stat(NextPath.c_str(),&statbuf)==-1)&& (errno=ENOTDIR))
  {
  	string stringN = NextPath.c_str();
  	string stringF = FirstPath.c_str();
  	string stringA = Appendix.c_str();
  	cout<<"stringN = "<<NextPath.c_str()<<endl;
  	cout<<"stringF = "<<FirstPath.c_str()<<endl;
  	cout<<"stringA = "<<Appendix.c_str()<<endl;
 	  pid_t childpid;
 	  childpid=fork();
 	  if(childpid==-1)
 	  {
 	  	cout<<"childpid =1"<<endl;
 	    cout<<strerror(errno) <<endl;
 	  }
 	  if(childpid==0)
 	  {cout<<"childpid = 0"<<endl;
 	  	/*********************************************************/
 	  	/****************** 函数 : chdir() **********************/
 	  	/*********************************************************/
 	  	/*        必要的 path 参数是一个字符串表达式             */
      /* 	 它指明哪个目录或文件夹将成为新的缺省目录或文件夹    */
      /* 	       	    path 可能会包含驱动器                    */
      /*                如果没有指定驱动器                     */
      /* 	  则 ChDir 在当前的驱动器上改变缺省目录或文件夹      */
      /*———————————————— 	 返回 : int 类型   —————————————————*/
 	  	/*********************************************************/
 	    chdir(FirstPath.c_str());                                               
 	    if( execl("/bin/mkdir","mkdir",Appendix.c_str(),NULL) !=-1 ) 
 	    {
 	    	cout<<"execl"<<endl;
 	     	return 0;
  	  }  
  	  else
  	  {
  	   	cout<<strerror(errno)<<endl;
  	  }
  	}
    if(childpid !=wait(NULL))                                                    //wait(NULL)返回第一个结束的childpid号
    {                                                                            //父进程进行
  	  cout<<"Parent failed to wait due to signal or error"<<endl;
  	  return 1;
  	}
 	}   
 	else
  {
  	cout<<"dir Exist !"<<endl;
 	  return 0;
 	}
 	return 0;
}

int PathCTL(string BaseLocalFilePath,string LocalCode,string Type,string Month)
{
	cout<<"PathCTL"<<endl;
  //struct stat statbuf;
  string nextPath=BaseLocalFilePath+"/"+LocalCode;
 	string nextNextPath=BaseLocalFilePath+"/"+LocalCode+"/"+Type;
 	string nextNextNextPath=BaseLocalFilePath+"/"+LocalCode+"/"+Type+"/"+Month;  
 	cout<<"nextPath : "<<nextPath<<endl;
 	cout<<"nextNextPath : "<<nextNextPath<<endl;
 	cout<<"nextNextNextPath : "<<nextNextNextPath<<endl;
 	if(FileNextPathControl(BaseLocalFilePath,nextPath,LocalCode)==0)
 	{   cout<<"1"<<endl;
 	 	if(FileNextPathControl(nextPath,nextNextPath,Type)==0)
 	  {    cout<<"2"<<endl;
 	  	if(FileNextPathControl(nextNextPath,nextNextNextPath,Month)==0)
 	    {     cout<<"3"<<endl;
 	     	 return 0;
 	    }
 	    else
 	    {
 	      cout<<strerror(errno) <<endl;
 	    }
 	  }
 	  else
 	  {   	
 	    cout<<strerror(errno) <<endl;
 	  }
 	}
 	else
 	{
 	 	cout<<strerror(errno) <<endl;
 	}
  return 0;	    
}
                                                                  //调试用函数main()
int main(int arg, char **argv)
{
	string username;
	string password;
	string connectString;
	//输入连接字符串
	string InputConnectString;
	cout<<"Please input the Connectstring  "<<endl;
	cin>>InputConnectString;
	//取字符串中的信息 xxx/xxx@xxx
	int possionf=0;
	int possions=0;
	possionf = InputConnectString.find('/',possionf);
	possions = InputConnectString.find('@',possions);
	cout<<"possionf:"<<possionf <<"*************possions:"<< possions<<endl;
	if(possionf!=string::npos && possions!=string::npos)
	{
		username = InputConnectString.substr(0,possionf);
		password = InputConnectString.substr(possionf+1,possions-possionf-1);
		connectString = InputConnectString.substr(possions+1,InputConnectString.length()-possions);
		//password = InputConnectString.substr(possionf+1,InputConnectString.length()-possionf);
		
		cout<<"username:"<<username<<endl;
		cout<<"password:"<<password<<endl;
		cout<<"connectString:"<<connectString<<endl;
		
	}else
	{
		cout<<"Input error"<<endl;	
	}
	//创建数据库的连接环境
	try{
				Environment *env = Environment::createEnvironment();
				Connection *conn = env->createConnection(username,password,connectString);
				string PrefixControlFile = "/sdata/IDM/cc/TestThree ";
				string ZipCode = "028";
				string ProgramName = "Test";
				string EndMonth = "200508";
				PathCTL(PrefixControlFile,ZipCode,ProgramName,EndMonth);
				
			
				env->terminateConnection(conn);
				Environment::terminateEnvironment(env);
				
				//输出结束连接到屏幕logtoscreen
				LogToScreen("Terminate","End the ConnEnvironment !!!");
	   }
	 catch(SQLException e)
	 {
	   		cout<<e.what();
   }
}
	
	
	
	
 
 
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -