我想在C中实现管道,例如 - $ ls | wc | wc
我写了以下代码 -
#include<stdio.h>
#include<stdlib.h>
#include <unistd.h>
void run_cmd(char *cmd, int* fd_in, int* fd_out)
{
int c = fork();
if (c==0)
{
if (fd_in != NULL)
{
close(fd_in[1]);
dup2(fd_in[0], 0);
}
if (fd_out != NULL)
{
close(fd_out[0]);
dup2(fd_out[1],1);
}
execlp(cmd, cmd, NULL);
}
}
int main(int argc, char **argv)
{
int fd_1[2], fd_2[2], i;
pipe(fd_1);
pipe(fd_2);
run_cmd(argv[1], NULL, fd_1);
for( i=2; i<argc-1; i++)
{
if (i%2 == 0)
run_cmd(argv[i], fd_1, fd_2);
else
run_cmd(argv[i], …Run Code Online (Sandbox Code Playgroud) 我正在尝试基于Zentask示例创建一个简单的登录 - zentask - playframework,但是当我单击调用Application.authenticate操作的登录按钮时,它会给出运行时异常.我用 - 错误标记了这一行
[RuntimeException: java.lang.reflect.InvocationTargetException]
Run Code Online (Sandbox Code Playgroud)
Application.java
public class Application extends Controller {
.........
public static class Login
{
public String email;
public String password;
public String validate()
{
if (User.authenticate(email, password) == null) {
return "Invalid user or password";
}
return null;
}
}
public static Result authenticate()
{
Form<Login> loginForm = form(Login.class).bindFromRequest(); //--- error
if(loginForm.hasErrors()) {
return badRequest(login.render(loginForm));
} else {
session("email", loginForm.get().email);
return redirect(
routes.Application.index()
);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我知道它与Login Class中的validate函数有关,因为当我在validate函数中删除对User.authenticate的调用时,它可以正常工作.但我无法弄明白.
用户类如下 - …
#include<stdio.h>
#include<stdlib.h>
#include<signal.h>
#include<unistd.h>
#include<sys/types.h>
void sighup()
{
signal(SIGHUP,sighup);
printf("Received SIGHUP! Happy Now ??\n");
}
void sigbus()
{
signal(SIGBUS,sigbus);
printf("received SIGBUS! Get a life dude !\n");
}
void sigquit()
{
printf("I am done with you. Bye!!\n");
fflush(stdout);
exit(0);
}
int main()
{
int pid = fork();
if (pid < 0)
{
perror("fork");
exit(1);
}
if (pid == 0)
{
printf("child\n");
signal(SIGHUP,sighup);
signal(SIGBUS,sigbus);
signal(SIGQUIT,sigquit);
while(1)
{
;
}
}
else
{
printf("parent\n");
kill(pid, SIGHUP);
kill(pid, SIGBUS);
kill(pid, SIGQUIT);
wait();
}
} …Run Code Online (Sandbox Code Playgroud) 我试图从 url ( https://windows.php.net/downloads/releases/php-7.2.9-nts-Win32-VC15-x64.zip )获取文件大小,这是我的代码 -
HttpWebRequest request = HttpWebRequest.CreateHttp(url);
HttpWebResponse response = (HttpWebResponse)(await request.GetResponseAsync());
long length = response.ContentLength;
Run Code Online (Sandbox Code Playgroud)
但价值length就是598 bytes,而网站(从浏览器下载时)报告的大小24.5MB。我什至尝试"Content-Length"从响应头访问,但它也具有相同的值598.
我错过了什么吗?有没有其他方法可以更准确地获取文件大小?
我有一个API ( https://www.readability.com/developers/api/parser#idm386426118064 ) 来提取网页的内容,但是在传递缩短的 url 或重定向到其他 url 时,它会出错。
我正在开发 Windows Phone 8.1 (xaml) 应用程序。有没有办法在c#或任何解决方法中获取目标网址?
我有一个Windows商店应用程序.该应用程序通过传递流媒体在MediaElement中播放音频,并在屏幕上随着音频的进展进行一些活动.但是当应用程序最小化时,音频"暂停"和活动,当应用程序最大化时,它将恢复.当应用程序最小化时,"OnSuspending"事件也不是触发器(我在该功能上设置断点并且它没有中断).
如何在最小化时停止应用程序"暂停".
我的应用程序有一个activitywith NavigationView和for导航抽屉中的不同项目UI通过更改来更改fragment.其中一个这样的片段已经TabLayout实现了.
当应用程序启动时fragment,TabLayout加载并且它工作正常,但是当我在其中的不同项目之间切换navigation drawer然后返回到具有该项目的项目时TabLayout,现在在滑动选项卡时,指示器卡在选项卡和一个选项卡上的内容之间甚至没有显示.我不清楚我可能犯了什么错误.我在用
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
Run Code Online (Sandbox Code Playgroud)
这是具有NavigationView(activity_start.xml)的活动
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_start"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_start"
app:menu="@menu/start_menu" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
这是app_bar_start.xml的代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.optimilia.readaloud.Start">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) android android-fragments android-tablayout android-navigationview
对于我的应用程序,我想在有人右键单击时显示自定义上下文菜单.如果右键单击任何单词,我想为它显示一些额外的选项.我抬头看网,我找到了解决方法,如何在单击时单击该单词,我尝试修改它以进行右键单击,但不知何故无法正常工作.
下面的代码,在左键单击时显示带有单词的警报,并且在进行右键单击时,它应该执行相同的操作.但有时它不显示任何弹出窗口,当它在弹出窗口中显示前一个右键单击的单词时.
$('.text123').click(function(e){
s = window.getSelection();
var range = s.getRangeAt(0);
var node = s.anchorNode;
while(range.toString().indexOf(' ') != 0) {
range.setStart(node,(range.startOffset -1));
}
range.setStart(node, range.startOffset +1);
do{
range.setEnd(node,range.endOffset + 1);
}while(range.toString().indexOf(' ') == -1 && range.toString().trim() != '');
var str = range.toString().trim();
alert(str);
});
$(".text123").mouseup(function(){
var e = window.event;
if (e.button == 2)
{
jQuery(document.elementFromPoint(e.pageX, e.pageY)).click();
}
});
Run Code Online (Sandbox Code Playgroud)
我在边缘浏览器上测试,因为我想在UWP应用程序中使用代码.