| 
          ubuntu12.04管理开机启动项目的方法 | 
        
                
          
            
                         一派護法 十九級              | 
          
            
            
            
              alt ctrl t 打开终端 gnome-session-properties               
                       | 
        
                
          
            
                         一派護法 十九級              | 
          
            
            
            
                       | 
        
                
          
            
                         一派護法 十九級              | 
          
            
            
             
              使用这种方法添加启动项要注意一个问题: 开机启动后,这个程序的工作目录为home/用户名,并不是程序所在目录!(这和windows下是一样的) 如果程序运行时输出了文件,则不能直接添加该程序到启动项中,应该添加sh文件。              
                        
           | 
        
                
          
            
                         一派護法 十九級              | 
          
            
            
             
              以以下程序为例,源代码: #include <iostream> #include <stdio.h> #include <time.h> #include <string> #include <memory.h>
  using namespace std;
  int main() {     //获取星期数     string month_en[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};     string month_zh[]={"一","二","三","四","五","六","日"};     int i;     time_t t=time(0);     char tmp[64];     strftime(tmp,sizeof(tmp),"%A",localtime(&t)); //获取星期英文字符串     for (i=0;i<7;i++)         if (month_en[i]==tmp)             break;     string str="%Y-%m-%d %X 星期";     str+=month_zh[i];     str+=" 开机 [本年第%j天 %z]\r\n";          //显示其他元素     memset(tmp,0,64);     strftime(tmp,sizeof(tmp),str.c_str(),localtime(&t)); //tmp变量为最终要写入文件的字符串     cout<<"Welcome!"<<endl;     cout<<tmp;          //写入文件     char filename[20];     strftime(filename,sizeof(filename),"powerlog_%Y.txt",localtime(&t)); //根据年份生成文件名     FILE* file=fopen(filename,"a"); //打开文件     fwrite(tmp,strlen(tmp),1,file); //应该用strlen而不是sizeof,否则会乱码     fclose(file);          return 0; }
  用g++编译后,不应该直接添加该程序为启动项。要先建立一个sh文件,这里我的文件名是autorun.sh: #!/bin/bash cd /home/octopus/程序/huber/powerlog ./powerlog
  然后添加该sh文件为启动项,然后重启/注销,会发现程序目录下多了个powerlog_2012.txt文件              
                        
              
               
             
           | 
        
                
          
            
                         一派護法 十九級              | 
          
            
            
            
              回复:5楼 如果是直接添加程序为启动项而不是sh文件的话,那么重启/注销,会发现新增的txt文件在home/用户名目录中。 (windows下也是这样,只不过不是home/用户名目录下)              
                        
           | 
        
                
          
            
                         一派護法 十九級              | 
          
            
            
             
              【补充】 其实用不着打开终端,先点最右上角的关机按钮再点“启动应用程序”也行。              
                        
           | 
        
                
          
            
                         一派護法 十九級              | 
          
            
            
            
                        
           | 
        
                
          
            
                         一派護法 十九級              | 
          
            
            
             
              英文版本: #include <iostream> #include <stdio.h> #include <time.h> #include <string> #include <memory.h>
  using namespace std;
  int main() {     time_t t=time(0);     char tmp[64];     strftime(tmp,sizeof(tmp),"%A",localtime(&t)); //Day of week     string str="%Y-%m-%d %X ";     str+=tmp;     str+=" [#%j %z] POWER ON\r\n";         memset(tmp,0,64); //reset the buffer     strftime(tmp,sizeof(tmp),str.c_str(),localtime(&t)); //Now tmp is the string to be written into the file and to be printed to the screen     cout<<"Welcome!"<<endl;     cout<<tmp;         //Write     char filename[20];     strftime(filename,sizeof(filename),"powerlog_%Y.txt",localtime(&t)); //filename     FILE* file=fopen(filename,"a"); //Open or create the file     fwrite(tmp,strlen(tmp),1,file); //use strlen instead of sizeof     fclose(file);         return 0; }
  makefile: powerlog: powerlog.cpp     g++ powerlog.cpp -o powerlog              
                        
           | 
        
                
          
            
                         一派護法 十九級              | 
          
            
            
            
              string month_es[]={"Lunes","Martes","Miércoles","Jueves","Viernes","Sábado","Domingo"};               
                        
           |