我有一个Java应用程序,它使用xml文件在开始时间内加载设置。我想在Linux、Windows和许多其他操作系统上运行此应用程序。
问题是文件路径在每个操作系统中都不同。我认为唯一的解决方案是获取操作系统平台类型,并根据它加载适当的配置文件:
/**
* helper class to check the operating system this Java VM runs in
*/
public static final class OsCheck {
/**
* types of Operating Systems
*/
public enum OSType {
我正在尝试用C语言保存一些文件,代码如下:
sprintf(playerinput,"%s",end);
sprintf(fileloc,"%s/.notend",getenv("HOME"));
playerdata = fopen(fileloc, "w+"); /*create the new file*/
if (!playerdata)
{
printf("\n\t\t\tCould not save settings file.");
return;
} else {
fputs(playeri
我想将linux中的find命令别名为一个函数,如果find命令的输出是文件系统上的文件或目录,该函数将打印绝对路径。
这是我到目前为止所得到的,但它不能正常工作。
find_with_abspath(){
for i in $(find "$@")
do
if [ -e "$i" ];
then
readlink -m "$i"
else
echo -n "$i"
fi
done
}
你知道我做
我编写了一个在ash下使用的shell脚本,并将stderr和stdout重定向到一个日志文件。我希望只有在stderr不为空的情况下才将该日志文件通过电子邮件发送给我。
我试过了:
exec >mylog.log 2>&1
# Perform various find commands
if [TEST_IF_STDERR_NOT_EMPTY]; then
/usr/bin/mail -s "mylog" email@mydomain.com < mylog.log
fi
我的问题有两个:
1-我得到一个-sh: /usr/bin/mail: n
我有一个需要运行构造函数的共享库(在Linux上是用C++写的,在Linux上是用gcc写的)。此构造函数需要处理一个配置文件,该文件可能位于与可执行文件相同的目录中,也可能位于另一个预定义的位置。换句话说,我需要知道库构造函数内部的argv[0]的值。那么正确的方法是什么呢? static void __attribute__((constructor)) mylib_init()
{
// need access to config file which is in the same directory as executable
}